Skip to content

Commit c795dda

Browse files
authored
Merge pull request #2179 from kofemann/drop-NullaryFunction
src: drop NullaryFunction in favor or java.util.Supplier
2 parents a80c366 + cb5fdde commit c795dda

File tree

25 files changed

+92
-181
lines changed

25 files changed

+92
-181
lines changed

modules/grizzly/src/main/java/org/glassfish/grizzly/Connection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import java.util.concurrent.Future;
2222
import java.util.concurrent.TimeUnit;
2323

24+
import java.util.function.Supplier;
2425
import org.glassfish.grizzly.attributes.AttributeStorage;
2526
import org.glassfish.grizzly.memory.MemoryManager;
2627
import org.glassfish.grizzly.monitoring.MonitoringAware;
2728
import org.glassfish.grizzly.monitoring.MonitoringConfig;
28-
import org.glassfish.grizzly.utils.NullaryFunction;
2929

3030
/**
3131
* Common interface, which represents any kind of connection.
@@ -152,7 +152,7 @@ public interface Connection<L> extends Readable<L>, Writeable<L>, Closeable, Att
152152
*
153153
* @return the {@link Processor} state associated with this <tt>Connection</tt>.
154154
*/
155-
<E> E obtainProcessorState(Processor processor, NullaryFunction<E> factory);
155+
<E> E obtainProcessorState(Processor processor, Supplier<E> factory);
156156

157157
/**
158158
* Executes the {@link Runnable} in the thread, responsible for running the given type of event on this

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/Attribute.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.glassfish.grizzly.attributes;
1818

19-
import org.glassfish.grizzly.utils.NullaryFunction;
19+
import java.util.function.Supplier;
2020

2121
/**
2222
* Class used to define dynamic typed attributes on {@link AttributeHolder} instances. Storing attribute values in
@@ -38,7 +38,7 @@ public final class Attribute<T> {
3838
/**
3939
* Attribute initializer, which will be called, if attribute is not set.
4040
*/
41-
private final NullaryFunction<T> initializer;
41+
private final Supplier<T> initializer;
4242
/**
4343
* Attribute index in AttributeBuilder
4444
*/
@@ -50,16 +50,16 @@ public String toString() {
5050
}
5151

5252
protected Attribute(final AttributeBuilder builder, final String name, final int index, final T defaultValue) {
53-
this(builder, name, index, new NullaryFunction<T>() {
53+
this(builder, name, index, new Supplier<T>() {
5454

5555
@Override
56-
public T evaluate() {
56+
public T get() {
5757
return defaultValue;
5858
}
5959
});
6060
}
6161

62-
protected Attribute(final AttributeBuilder builder, final String name, final int index, final NullaryFunction<T> initializer) {
62+
protected Attribute(final AttributeBuilder builder, final String name, final int index, final Supplier<T> initializer) {
6363
this.builder = builder;
6464
this.name = name;
6565
this.attributeIndex = index;
@@ -68,7 +68,7 @@ protected Attribute(final AttributeBuilder builder, final String name, final int
6868

6969
/**
7070
* Get attribute value, stored on the {@link AttributeHolder}, the difference from
71-
* {@link #get(org.glassfish.grizzly.attributes.AttributeHolder)} is that default value or {@link NullaryFunction} won't
71+
* {@link #get(org.glassfish.grizzly.attributes.AttributeHolder)} is that default value or {@link Supplier} won't
7272
* be invoked.
7373
*
7474
* @param attributeHolder {@link AttributeHolder}.
@@ -80,7 +80,7 @@ public T peek(final AttributeHolder attributeHolder) {
8080

8181
/**
8282
* Get attribute value, stored on the {@link AttributeStorage}, the difference from {@link #get(AttributeStorage)} is
83-
* that default value or {@link NullaryFunction} won't be invoked.
83+
* that default value or {@link Supplier} won't be invoked.
8484
*
8585
* @param storage {@link AttributeStorage}.
8686
* @return attribute value
@@ -212,7 +212,7 @@ public int index() {
212212
}
213213

214214
@SuppressWarnings("unchecked")
215-
private T get0(final AttributeHolder attributeHolder, final NullaryFunction<T> initializer) {
215+
private T get0(final AttributeHolder attributeHolder, final Supplier<T> initializer) {
216216
final IndexedAttributeAccessor indexedAccessor = attributeHolder.getIndexedAttributeAccessor();
217217

218218
return indexedAccessor != null ? (T) indexedAccessor.getAttribute(attributeIndex, initializer) : (T) attributeHolder.getAttribute(name, initializer);

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeBuilder.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.glassfish.grizzly.attributes;
1818

19+
import java.util.function.Supplier;
20+
1921
/**
2022
* <tt>AttributeBuilder</tt> is responsible for creating and indexing {@link Attribute}s. For faster access to
2123
* {@link Attribute} value, each {@link Attribute} has assigned index. <tt>AttributeBuilder</tt> is responsible to
@@ -61,29 +63,18 @@ public interface AttributeBuilder {
6163
*/
6264
<T> Attribute<T> createAttribute(String name, T defaultValue);
6365

64-
/**
65-
* Create Attribute with name and initializer, which will be called, if Attribute's value is null on a AttributedObject
66-
*
67-
* @param <T> Type of attribute value
68-
* @param name attribute name
69-
* @param initializer NullaryFunction, which will be called, if Attribute's value is null on a AttributedObject
70-
*
71-
* @return Attribute<T>
72-
*/
73-
<T> Attribute<T> createAttribute(String name, org.glassfish.grizzly.utils.NullaryFunction<T> initializer);
7466

7567
/**
7668
* Create Attribute with name and initializer, which will be called, if Attribute's value is null on a AttributedObject
7769
*
7870
* @param <T> Type of attribute value
7971
* @param name attribute name
80-
* @param initializer NullaryFunction, which will be called, if Attribute's value is null on a AttributedObject
72+
* @param initializer {@link Supplier}, which will be called, if Attribute's value is null on a AttributedObject
8173
*
8274
* @return Attribute<T>
83-
* @deprecated pls. use {@link #createAttribute(java.lang.String, org.glassfish.grizzly.utils.NullaryFunction)}.
8475
*/
8576
@Deprecated
86-
<T> Attribute<T> createAttribute(String name, NullaryFunction<T> initializer);
77+
<T> Attribute<T> createAttribute(String name, Supplier<T> initializer);
8778

8879
/**
8980
* Creates and returns new thread-safe {@link AttributeHolder}

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeHolder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Set;
2020

21-
import org.glassfish.grizzly.utils.NullaryFunction;
21+
import java.util.function.Supplier;
2222

2323
/**
2424
* Interface declares common functionality for objects, which have associated {@link Attribute}s.
@@ -62,7 +62,7 @@ public interface AttributeHolder {
6262
*
6363
* @since 2.3.18
6464
*/
65-
Object getAttribute(String name, NullaryFunction initializer);
65+
Object getAttribute(String name, Supplier initializer);
6666

6767
/**
6868
* Return a {@link Set} of attribute names.

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/DefaultAttributeBuilder.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24-
import org.glassfish.grizzly.utils.NullaryFunction;
24+
import java.util.function.Supplier;
2525

2626
/**
2727
* Default {@link AttributeBuilder} implementation.
@@ -63,7 +63,7 @@ public synchronized <T> Attribute<T> createAttribute(final String name, final T
6363
*/
6464
@Override
6565
@SuppressWarnings("unchecked")
66-
public synchronized <T> Attribute<T> createAttribute(final String name, final NullaryFunction<T> initializer) {
66+
public synchronized <T> Attribute<T> createAttribute(final String name, final Supplier<T> initializer) {
6767
Attribute<T> attribute = name2Attribute.get(name);
6868
if (attribute == null) {
6969
attribute = new Attribute<>(this, name, attributes.size(), initializer);
@@ -74,17 +74,6 @@ public synchronized <T> Attribute<T> createAttribute(final String name, final Nu
7474
return attribute;
7575
}
7676

77-
@Override
78-
public <T> Attribute<T> createAttribute(final String name, final org.glassfish.grizzly.attributes.NullaryFunction<T> initializer) {
79-
return createAttribute(name, initializer == null ? null : new NullaryFunction<T>() {
80-
81-
@Override
82-
public T evaluate() {
83-
return initializer.evaluate();
84-
}
85-
});
86-
}
87-
8877
@Override
8978
public AttributeHolder createSafeAttributeHolder() {
9079
return new IndexedAttributeHolder(this);

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/IndexedAttributeAccessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.glassfish.grizzly.attributes;
1818

19-
import org.glassfish.grizzly.utils.NullaryFunction;
19+
import java.util.function.Supplier;
2020

2121
/**
2222
* The interface declares, that {@link AttributeHolder} supports indexed {@link Attribute} access.
@@ -38,11 +38,11 @@ public interface IndexedAttributeAccessor {
3838
* index is not set, set it to the default value, using the <tt>initializer</tt>, and return the default.
3939
*
4040
* @param index the attribute index
41-
* @param initializer the default value {@link NullaryFunction}
41+
* @param initializer the default value {@link Supplier}
4242
* @return the value of the attribute by index
4343
* @since 2.3.18
4444
*/
45-
Object getAttribute(int index, NullaryFunction initializer);
45+
Object getAttribute(int index, Supplier initializer);
4646

4747
/**
4848
* Internal method for dynamic attribute support. Set the attribute with the index to value.

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/IndexedAttributeHolder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24-
import org.glassfish.grizzly.utils.NullaryFunction;
24+
import java.util.function.Supplier;
2525

2626
/**
2727
* {@link AttributeHolder}, which supports indexed access to stored {@link Attribute}s. Access to such indexed
@@ -69,7 +69,7 @@ public Object getAttribute(final String name) {
6969
* {@inheritDoc}
7070
*/
7171
@Override
72-
public Object getAttribute(final String name, final NullaryFunction initializer) {
72+
public Object getAttribute(final String name, final Supplier initializer) {
7373
final Attribute attribute = attributeBuilder.getAttributeByName(name);
7474
if (attribute != null) {
7575
return indexedAttributeAccessor.getAttribute(attribute.index(), initializer);
@@ -293,17 +293,17 @@ public Object getAttribute(final int index) {
293293
* {@inheritDoc}
294294
*/
295295
@Override
296-
public Object getAttribute(final int index, final NullaryFunction initializer) {
296+
public Object getAttribute(final int index, final Supplier initializer) {
297297
Object value = weakGet(index);
298298

299299
if (value == null && initializer != null) {
300300
synchronized (sync) {
301-
// we want to make sure that parallel getAttribute(int, NullaryFunction)
302-
// won't create multiple value instances (everyone will call NullaryFunction.evaluate())
301+
// we want to make sure that parallel getAttribute(int, Suppler)
302+
// won't create multiple value instances (everyone will call Supplier.get())
303303
value = weakGet(index);
304304

305305
if (value == null) {
306-
value = initializer.evaluate();
306+
value = initializer.get();
307307
setAttribute(index, value);
308308
}
309309
}

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/NullaryFunction.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/UnsafeAttributeHolder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Map;
2222
import java.util.Set;
2323

24-
import org.glassfish.grizzly.utils.NullaryFunction;
24+
import java.util.function.Supplier;
2525

2626
/**
2727
* A non thread-safe {@link AttributeHolder} implementation.
@@ -57,7 +57,7 @@ public Object getAttribute(final String name) {
5757
}
5858

5959
@Override
60-
public Object getAttribute(final String name, final NullaryFunction initializer) {
60+
public Object getAttribute(final String name, final Supplier initializer) {
6161

6262
if (!isSet && initializer == null) {
6363
return null;
@@ -68,7 +68,7 @@ public Object getAttribute(final String name, final NullaryFunction initializer)
6868
return indexedAttributeAccessor.getAttribute(attribute, initializer);
6969
}
7070

71-
return initializer != null ? initializer.evaluate() : null;
71+
return initializer != null ? initializer.get() : null;
7272
}
7373

7474
@Override
@@ -238,7 +238,7 @@ public Object getAttribute(final int index) {
238238
}
239239

240240
@Override
241-
public Object getAttribute(final int index, final NullaryFunction initializer) {
241+
public Object getAttribute(final int index, final Supplier initializer) {
242242
if (!isSet && initializer == null) {
243243
return null;
244244
}
@@ -256,14 +256,14 @@ public Object removeAttribute(final int index) {
256256
return removeAttribute(attributeBuilder.getAttributeByIndex(index));
257257
}
258258

259-
private Object getAttribute(final Attribute attribute, final NullaryFunction initializer) {
259+
private Object getAttribute(final Attribute attribute, final Supplier initializer) {
260260
final int idx = attribute.index();
261261

262262
final Holder h = holderByIdx(idx);
263263

264264
if (h != null) {
265265
if (h.value == null && initializer != null) {
266-
h.value = initializer.evaluate();
266+
h.value = initializer.get();
267267
}
268268

269269
return h.value;
@@ -272,7 +272,7 @@ private Object getAttribute(final Attribute attribute, final NullaryFunction ini
272272
Object value = valueMap != null ? MapperAccessor.getValue(UnsafeAttributeHolder.this, idx) : null;
273273

274274
if (value == null && initializer != null) {
275-
value = initializer.evaluate();
275+
value = initializer.get();
276276
setAttribute(attribute, value);
277277
}
278278

modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/DefaultFilterChain.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Collection;
2222
import java.util.concurrent.ExecutionException;
23+
import java.util.function.Supplier;
2324
import java.util.logging.Level;
2425
import java.util.logging.Logger;
2526

@@ -44,7 +45,6 @@
4445
import org.glassfish.grizzly.memory.Buffers;
4546
import org.glassfish.grizzly.utils.Exceptions;
4647
import org.glassfish.grizzly.utils.Futures;
47-
import org.glassfish.grizzly.utils.NullaryFunction;
4848

4949
/**
5050
* Default {@link FilterChain} implementation
@@ -637,10 +637,10 @@ private Object append(final Object currentMessage) {
637637
}
638638
}
639639

640-
private final class FiltersStateFactory implements NullaryFunction<FiltersState> {
640+
private final class FiltersStateFactory implements Supplier<FiltersState> {
641641

642642
@Override
643-
public FiltersState evaluate() {
643+
public FiltersState get() {
644644
return new FiltersState(size());
645645
}
646646
}

0 commit comments

Comments
 (0)