update some log model

This commit is contained in:
Edouard DUPIN 2022-04-11 00:49:53 +02:00
parent 44b4062903
commit 0dc3ad94c0
3 changed files with 59 additions and 62 deletions

View File

@ -19,7 +19,7 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue;
* signalEvent.setCallBackNotification(this::onConnectionChange);
* }
* public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) {
* Log.info("Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection);
* Log.info("Number of connection Change : {} dalta={}", currentNumberConnection, deltaConnection);
* }
* }
* }</pre>
@ -53,7 +53,7 @@ public class ISignal<T> extends GenericSignalInstrumented<Consumer<T>, BiConsume
* @param value Value to set in parameter.
*/
public void emit(final T value) {
List<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> tmp = getACleanedList();
final List<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> tmp = getACleanedList();
if (tmp == null) {
return;
}
@ -62,17 +62,17 @@ public class ISignal<T> extends GenericSignalInstrumented<Consumer<T>, BiConsume
while (iterator.hasNext()) {
final ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>> elem = iterator.next();
Object remoteLockObject = elem.lockObjects();
final Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) {
continue;
}
Consumer<T> tmpConsumer = elem.getConsumer();
final Consumer<T> tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) {
tmpConsumer.accept(value);
continue;
}
// Not a dead code, but very hard to simply test it.
BiConsumer<Object, T> tmpConsumer2 = elem.getConsumer2();
final BiConsumer<Object, T> tmpConsumer2 = elem.getConsumer2();
if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject(), value);
}

View File

@ -18,41 +18,19 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue;
* signalEvent.setCallBackNotification(this::onConnectionChange);
* }
* public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) {
* Log.info("Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection);
* Log.info("Number of connection Change : {} delta={}", currentNumberConnection, deltaConnection);
* }
* }
* }</pre>
*
*/
public class ISignalEmpty extends GenericSignalInstrumented<Runnable, Consumer<Object>> {
/**
* Emit a signal on all element connect (and clean the list of unlinked elements).
*/
public void emit() {
List<ConnectedElementInterface<Runnable, Consumer<Object>>> tmp = getACleanedList();
if (tmp == null) {
return;
}
// real call elements
final Iterator<ConnectedElementInterface<Runnable, Consumer<Object>>> iterator = tmp.iterator();
while (iterator.hasNext()) {
final ConnectedElementInterface<Runnable, Consumer<Object>> elem = iterator.next();
Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) {
continue;
}
Runnable tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) {
tmpConsumer.run();
continue;
}
// Not a dead code, but very hard to simply test it.
Consumer<Object> tmpConsumer2 = elem.getConsumer2();
if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject());
}
}
@CheckReturnValue
@SuppressWarnings("unchecked")
public <V> Connection connect(final V object, final Consumer<V> function) {
return connect(object, (final Object obj) -> {
function.accept((V) obj);
});
}
/**
@ -62,19 +40,39 @@ public class ISignalEmpty extends GenericSignalInstrumented<Runnable, Consumer<O
*/
@SuppressWarnings("unchecked")
public <V> void connectAuto(final V object, final Consumer<V> function) {
connectAuto(object,
(final Object obj) -> {
function.accept((V)obj);
connectAuto(object, (final Object obj) -> {
function.accept((V) obj);
});
}
@CheckReturnValue
@SuppressWarnings("unchecked")
public <V> Connection connect(final V object, final Consumer<V> function) {
return connect(object,
(final Object obj) -> {
function.accept((V)obj);
});
/**
* Emit a signal on all element connect (and clean the list of unlinked elements).
*/
public void emit() {
final List<ConnectedElementInterface<Runnable, Consumer<Object>>> tmp = getACleanedList();
if (tmp == null) {
return;
}
// real call elements
final Iterator<ConnectedElementInterface<Runnable, Consumer<Object>>> iterator = tmp.iterator();
while (iterator.hasNext()) {
final ConnectedElementInterface<Runnable, Consumer<Object>> elem = iterator.next();
final Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) {
continue;
}
final Runnable tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) {
tmpConsumer.run();
continue;
}
// Not a dead code, but very hard to simply test it.
final Consumer<Object> tmpConsumer2 = elem.getConsumer2();
if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject());
}
}
}
}

View File

@ -18,12 +18,12 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue;
*
* class ReceiverSimple {
* public void onEvent(String data) {
* Log.error("function receive: " + data);
* Log.error("function receive: {}", data);
* }
* public connectLambda(EmiterSimple other) {
* // Note : this lambda is reference a a global, then it will never removed in the connection list ==> refer the local class or @see connectAutoRemoveObject
* other.signalEvent.connect((data) -> {
* Log.error("lambda receive: " + data);
* Log.error("lambda receive: {}", data);
* });
* }
* }
@ -54,35 +54,12 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue;
*
*/
public class Signal<T> extends GenericSignal<Consumer<T>, BiConsumer<Object, T>> {
/**
* Emit a signal on all element connect (and clean the list of unlinked elements).
* @param value Value to set in parameter.
*/
public void emit(final T value) {
List<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> tmp = getACleanedList();
if (tmp == null) {
return;
}
// real call elements
final Iterator<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> iterator = tmp.iterator();
while (iterator.hasNext()) {
final ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>> elem = iterator.next();
Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) {
continue;
}
Consumer<T> tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) {
tmpConsumer.accept(value);
continue;
}
// Not a dead code, but very hard to simply test it.
BiConsumer<Object, T> tmpConsumer2 = elem.getConsumer2();
if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject(), value);
}
}
@CheckReturnValue
@SuppressWarnings("unchecked")
public <V> Connection connect(final V object, final BiConsumer<V, T> function) {
return connect(object, (final Object obj, final T value) -> {
function.accept((V) obj, value);
});
}
/**
@ -92,17 +69,39 @@ public class Signal<T> extends GenericSignal<Consumer<T>, BiConsumer<Object, T>>
*/
@SuppressWarnings("unchecked")
public <V> void connectAuto(final V object, final BiConsumer<V, T> function) {
connectAuto(object,
(final Object obj, final T value) -> {
function.accept((V)obj, value);
connectAuto(object, (final Object obj, final T value) -> {
function.accept((V) obj, value);
});
}
@CheckReturnValue
@SuppressWarnings("unchecked")
public <V> Connection connect(final V object, final BiConsumer<V, T> function) {
return connect(object,
(final Object obj, final T value) -> {
function.accept((V)obj, value);
});
/**
* Emit a signal on all element connect (and clean the list of unlinked elements).
* @param value Value to set in parameter.
*/
public void emit(final T value) {
final List<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> tmp = getACleanedList();
if (tmp == null) {
return;
}
// real call elements
final Iterator<ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>>> iterator = tmp.iterator();
while (iterator.hasNext()) {
final ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>> elem = iterator.next();
final Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) {
continue;
}
final Consumer<T> tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) {
tmpConsumer.accept(value);
continue;
}
// Not a dead code, but very hard to simply test it.
final BiConsumer<Object, T> tmpConsumer2 = elem.getConsumer2();
if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject(), value);
}
}
}
}