Skip to content

Commit

Permalink
MID-4570 npe fix, minor copy and paste fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 7, 2018
1 parent 278274b commit 40bf68e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
Expand Up @@ -17,27 +17,24 @@

/**
* Dispatcher of change notifications.
*
*
* Instances that implement this interface relay notification from the source of the change notification to the
* destinations. The destinations are chosen dynamically, using a publish-subscribe mechanism.
*
*
* This interface also includes ResourceObjectChangeListener. By invoking the notifyChange(..) operation of this
* interface the change will be relayed to all registered listeners.
*
*
* @author Katka Valalikova
* @author Radovan Semancik
*
*/
public interface ChangeNotificationDispatcher extends ResourceObjectChangeListener, ResourceOperationListener, ResourceEventListener {

public void registerNotificationListener(ResourceObjectChangeListener listener);
public void registerNotificationListener(ResourceOperationListener listener);
public void registerNotificationListener(ResourceEventListener listener);

public void unregisterNotificationListener(ResourceObjectChangeListener listener);
public void unregisterNotificationListener(ResourceOperationListener listener);
public void unregisterNotificationListener(ResourceEventListener listener);




void registerNotificationListener(ResourceObjectChangeListener listener);
void registerNotificationListener(ResourceOperationListener listener);
void registerNotificationListener(ResourceEventListener listener);

void unregisterNotificationListener(ResourceObjectChangeListener listener);
void unregisterNotificationListener(ResourceOperationListener listener);
void unregisterNotificationListener(ResourceEventListener listener);
}
Expand Up @@ -69,6 +69,8 @@ public void setFilterProtectedObjects(boolean filterProtectedObjects) {
*/
@Override
public synchronized void registerNotificationListener(ResourceObjectChangeListener listener) {
Validate.notNull(listener);

if (changeListeners.contains(listener)) {
LOGGER.warn(
"Resource object change listener '{}' is already registered. Subsequent registration is ignored",
Expand All @@ -84,6 +86,8 @@ public synchronized void registerNotificationListener(ResourceObjectChangeListen
*/
@Override
public synchronized void registerNotificationListener(ResourceOperationListener listener) {
Validate.notNull(listener);

if (operationListeners.contains(listener)) {
LOGGER.warn(
"Resource operation listener '{}' is already registered. Subsequent registration is ignored",
Expand All @@ -95,6 +99,8 @@ public synchronized void registerNotificationListener(ResourceOperationListener
}
@Override
public synchronized void registerNotificationListener(ResourceEventListener listener) {
Validate.notNull(listener);

if (eventListeners.contains(listener)) {
LOGGER.warn(
"Resource event listener '{}' is already registered. Subsequent registration is ignored",
Expand Down Expand Up @@ -147,7 +153,8 @@ public void notifyChange(ResourceObjectShadowChangeDescription change, Task task
} catch (RuntimeException e) {
LOGGER.error("Exception {} thrown by object change listener {}: {}", e.getClass(), listener.getName(),
e.getMessage(), e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyChange").recordWarning("Change listener has thrown unexpected exception", e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyChange")
.recordWarning("Change listener has thrown unexpected exception", e);
throw e;
}
}
Expand All @@ -170,15 +177,16 @@ public void notifyFailure(ResourceOperationDescription failureDescription,

failureDescription.checkConsistence();

if ((null != changeListeners) && (!changeListeners.isEmpty())) {
if ((null != operationListeners) && (!operationListeners.isEmpty())) {
for (ResourceOperationListener listener : new ArrayList<>(operationListeners)) { // sometimes there is registration/deregistration from within
//LOGGER.trace("Listener: {}", listener.getClass().getSimpleName());
try {
listener.notifyFailure(failureDescription, task, parentResult);
} catch (RuntimeException e) {
LOGGER.error("Exception {} thrown by operation failure listener {}: {}-{}", new Object[]{
e.getClass(), listener.getName(), e.getMessage(), e });
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyFailure").recordWarning("Operation failure listener has thrown unexpected exception", e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyFailure")
.recordWarning("Operation failure listener has thrown unexpected exception", e);
}
}
} else {
Expand All @@ -190,25 +198,26 @@ public void notifyFailure(ResourceOperationDescription failureDescription,
* @see com.evolveum.midpoint.provisioning.api.ResourceObjectChangeListener#notifyFailure(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowFailureDescription, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public void notifySuccess(ResourceOperationDescription failureDescription,
public void notifySuccess(ResourceOperationDescription successDescription,
Task task, OperationResult parentResult) {
Validate.notNull(failureDescription, "Operation description of resource object shadow must not be null.");
Validate.notNull(successDescription, "Operation description of resource object shadow must not be null.");

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Resource operation success notification\n{} ", failureDescription.debugDump());
LOGGER.trace("Resource operation success notification\n{} ", successDescription.debugDump());
}

failureDescription.checkConsistence();
successDescription.checkConsistence();

if ((null != changeListeners) && (!changeListeners.isEmpty())) {
if ((null != operationListeners) && (!operationListeners.isEmpty())) {
for (ResourceOperationListener listener : new ArrayList<>(operationListeners)) { // sometimes there is registration/deregistration from within
//LOGGER.trace("Listener: {}", listener.getClass().getSimpleName());
try {
listener.notifySuccess(failureDescription, task, parentResult);
listener.notifySuccess(successDescription, task, parentResult);
} catch (RuntimeException e) {
LOGGER.error("Exception {} thrown by operation success listener {}: {}-{}", new Object[]{
e.getClass(), listener.getName(), e.getMessage(), e });
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifySuccess").recordWarning("Operation success listener has thrown unexpected exception", e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifySuccess")
.recordWarning("Operation success listener has thrown unexpected exception", e);
}
}
} else {
Expand All @@ -220,25 +229,26 @@ public void notifySuccess(ResourceOperationDescription failureDescription,
* @see com.evolveum.midpoint.provisioning.api.ResourceObjectChangeListener#notifyFailure(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowFailureDescription, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public void notifyInProgress(ResourceOperationDescription failureDescription,
public void notifyInProgress(ResourceOperationDescription inProgressDescription,
Task task, OperationResult parentResult) {
Validate.notNull(failureDescription, "Operation description of resource object shadow must not be null.");
Validate.notNull(inProgressDescription, "Operation description of resource object shadow must not be null.");

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Resource operation in-progress notification\n{} ", failureDescription.debugDump());
LOGGER.trace("Resource operation in-progress notification\n{} ", inProgressDescription.debugDump());
}

failureDescription.checkConsistence();
inProgressDescription.checkConsistence();

if ((null != changeListeners) && (!changeListeners.isEmpty())) {
if ((null != operationListeners) && (!operationListeners.isEmpty())) {
for (ResourceOperationListener listener : new ArrayList<>(operationListeners)) { // sometimes there is registration/deregistration from within
//LOGGER.trace("Listener: {}", listener.getClass().getSimpleName());
try {
listener.notifyInProgress(failureDescription, task, parentResult);
listener.notifyInProgress(inProgressDescription, task, parentResult);
} catch (RuntimeException e) {
LOGGER.error("Exception {} thrown by operation in-progress listener {}: {}-{}", new Object[]{
e.getClass(), listener.getName(), e.getMessage(), e });
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyInProgress").recordWarning("Operation in-progress listener has thrown unexpected exception", e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyInProgress")
.recordWarning("Operation in-progress listener has thrown unexpected exception", e);
}
}
} else {
Expand Down Expand Up @@ -281,7 +291,8 @@ public void notifyEvent(ResourceEventDescription eventDescription,
} catch (RuntimeException e) {
LOGGER.error("Exception {} thrown by event listener {}: {}-{}", new Object[]{
e.getClass(), listener.getName(), e.getMessage(), e });
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyEvent").recordWarning("Event listener has thrown unexpected exception", e);
parentResult.createSubresult(CLASS_NAME_WITH_DOT + "notifyEvent")
.recordWarning("Event listener has thrown unexpected exception", e);
throw e;
}
}
Expand Down

0 comments on commit 40bf68e

Please sign in to comment.