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); * signalEvent.setCallBackNotification(this::onConnectionChange);
* } * }
* public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { * 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> * }</pre>
@ -53,7 +53,7 @@ public class ISignal<T> extends GenericSignalInstrumented<Consumer<T>, BiConsume
* @param value Value to set in parameter. * @param value Value to set in parameter.
*/ */
public void emit(final T value) { 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) { if (tmp == null) {
return; return;
} }
@ -62,17 +62,17 @@ public class ISignal<T> extends GenericSignalInstrumented<Consumer<T>, BiConsume
while (iterator.hasNext()) { while (iterator.hasNext()) {
final ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>> elem = iterator.next(); final ConnectedElementInterface<Consumer<T>, BiConsumer<Object, T>> elem = iterator.next();
Object remoteLockObject = elem.lockObjects(); final Object remoteLockObject = elem.lockObjects();
if (elem.isObjectDependent() && remoteLockObject == null) { if (elem.isObjectDependent() && remoteLockObject == null) {
continue; continue;
} }
Consumer<T> tmpConsumer = elem.getConsumer(); final Consumer<T> tmpConsumer = elem.getConsumer();
if (tmpConsumer != null) { if (tmpConsumer != null) {
tmpConsumer.accept(value); tmpConsumer.accept(value);
continue; continue;
} }
// Not a dead code, but very hard to simply test it. // 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) { if (tmpConsumer2 != null) {
tmpConsumer2.accept(elem.getObject(), value); tmpConsumer2.accept(elem.getObject(), value);
} }

View File

@ -18,41 +18,19 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue;
* signalEvent.setCallBackNotification(this::onConnectionChange); * signalEvent.setCallBackNotification(this::onConnectionChange);
* } * }
* public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { * 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> * }</pre>
* *
*/ */
public class ISignalEmpty extends GenericSignalInstrumented<Runnable, Consumer<Object>> { public class ISignalEmpty extends GenericSignalInstrumented<Runnable, Consumer<Object>> {
/** @CheckReturnValue
* Emit a signal on all element connect (and clean the list of unlinked elements). @SuppressWarnings("unchecked")
*/ public <V> Connection connect(final V object, final Consumer<V> function) {
public void emit() { return connect(object, (final Object obj) -> {
List<ConnectedElementInterface<Runnable, Consumer<Object>>> tmp = getACleanedList(); function.accept((V) obj);
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());
}
}
} }
/** /**
@ -62,19 +40,39 @@ public class ISignalEmpty extends GenericSignalInstrumented<Runnable, Consumer<O
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <V> void connectAuto(final V object, final Consumer<V> function) { public <V> void connectAuto(final V object, final Consumer<V> function) {
connectAuto(object, connectAuto(object, (final Object obj) -> {
(final Object obj) -> { function.accept((V) obj);
function.accept((V)obj);
}); });
} }
@CheckReturnValue /**
@SuppressWarnings("unchecked") * Emit a signal on all element connect (and clean the list of unlinked elements).
public <V> Connection connect(final V object, final Consumer<V> function) { */
return connect(object, public void emit() {
(final Object obj) -> { final List<ConnectedElementInterface<Runnable, Consumer<Object>>> tmp = getACleanedList();
function.accept((V)obj); 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 { * class ReceiverSimple {
* public void onEvent(String data) { * public void onEvent(String data) {
* Log.error("function receive: " + data); * Log.error("function receive: {}", data);
* } * }
* public connectLambda(EmiterSimple other) { * 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 * // 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) -> { * 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>> { public class Signal<T> extends GenericSignal<Consumer<T>, BiConsumer<Object, T>> {
/** @CheckReturnValue
* Emit a signal on all element connect (and clean the list of unlinked elements). @SuppressWarnings("unchecked")
* @param value Value to set in parameter. public <V> Connection connect(final V object, final BiConsumer<V, T> function) {
*/ return connect(object, (final Object obj, final T value) -> {
public void emit(final T value) { function.accept((V) obj, 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);
}
}
} }
/** /**
@ -92,17 +69,39 @@ public class Signal<T> extends GenericSignal<Consumer<T>, BiConsumer<Object, T>>
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <V> void connectAuto(final V object, final BiConsumer<V, T> function) { public <V> void connectAuto(final V object, final BiConsumer<V, T> function) {
connectAuto(object, connectAuto(object, (final Object obj, final T value) -> {
(final Object obj, final T value) -> { function.accept((V) obj, value);
function.accept((V)obj, value);
}); });
} }
@CheckReturnValue
@SuppressWarnings("unchecked") /**
public <V> Connection connect(final V object, final BiConsumer<V, T> function) { * Emit a signal on all element connect (and clean the list of unlinked elements).
return connect(object, * @param value Value to set in parameter.
(final Object obj, final T value) -> { */
function.accept((V)obj, value); 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);
}
}
} }
} }