Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions celements-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<artifactId>celements-config-source</artifactId>
<version>7.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-observation</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.celements</groupId>
<artifactId>celements-subsystem-migration-manager</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
com.celements.xwikiPatches.SpacePreferencesConfigurationSource
com.celements.common.observation.listener.LocalEventListener
com.celements.configuration.CelementsDefaultConfigurationSource
com.celements.configuration.CelementsAllConfigurationSource
com.celements.store.CelHibernateStore
13 changes: 3 additions & 10 deletions celements-observation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,11 @@

<!-- testing -->
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>

<!-- xwiki legacy testing -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-core-shared-tests</artifactId>
<groupId>com.celements</groupId>
<artifactId>celements-base-tests</artifactId>
<version>7.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

</dependencies>
<scm>
<connection>scm:git:git@github.com:celements/celements-base.git</connection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.event.AllEvent;
import org.xwiki.observation.event.Event;
import org.xwiki.observation.remote.LocalEventData;
import org.xwiki.observation.remote.internal.OutgoingObservationManager;

/**
* Default implementation of the {@link ObservationManager}.
Expand Down Expand Up @@ -75,6 +77,9 @@ public class DefaultObservationManager implements ObservationManager, Initializa
@Requirement
private ComponentManager componentManager;

@Requirement
private OutgoingObservationManager outgoingObservationManager;

/**
* Helper class to store the list of events of a given type associated with a given listener. We
* need this for performance reasons and also in order to be able to add events after a listener
Expand Down Expand Up @@ -215,12 +220,23 @@ public EventListener getListener(String listenerName) {

@Override
public void notify(Event event, Object source, Object data) {
var localEvent = new LocalEventData(event, source, data);
if (outgoingObservationManager.isEnabled()) {
outgoingObservationManager.notifyLocalThenRemote(localEvent, this::notify);
} else {
notify(localEvent);
}
}

private void notify(LocalEventData localEvent) {
Event event = localEvent.getEvent();
Object source = localEvent.getSource();
Object data = localEvent.getData();
// Find all listeners for this event
Map<String, RegisteredListener> regListeners = this.listenersByEvent.get(event.getClass());
if (regListeners != null) {
notify(regListeners.values(), event, source, data);
}

// Find listener listening all events
Map<String, RegisteredListener> allEventRegListeners = this.listenersByEvent
.get(AllEvent.class);
Expand Down

This file was deleted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping "Remote" from the name makes IncomingObservationManager and OutgoingObservationManager sound like generic local event routers.

Rename to IncomingRemoteObservationManager (or RemoteEventReceiver). This immediately signals that it handles network-bound events, avoiding confusion with the core ObservationManager.

Original file line number Diff line number Diff line change
Expand Up @@ -32,70 +32,28 @@
import org.xwiki.context.ExecutionContextException;
import org.xwiki.context.ExecutionContextManager;
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.event.ApplicationStoppedEvent;
import org.xwiki.observation.remote.LocalEventData;
import org.xwiki.observation.remote.NetworkAdapter;
import org.xwiki.observation.remote.RemoteEventData;
import org.xwiki.observation.remote.RemoteObservationManager;
import org.xwiki.observation.remote.RemoteObservationManagerConfiguration;
import org.xwiki.observation.remote.RemoteObservationManagerContext;
import org.xwiki.observation.remote.converter.EventConverterManager;

/**
* JGoups based {@link RemoteObservationManager}. It's also the default implementation for now.
*
* @version $Id$
* @since 2.0M3
*/
@Service
public class DefaultRemoteObservationManager implements RemoteObservationManager {
public class IncomingObservationManager {

private static final Logger LOGGER = LoggerFactory
.getLogger(DefaultRemoteObservationManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(IncomingObservationManager.class);

/**
* Access {@link RemoteObservationManager} configuration.
*/
private final RemoteObservationManagerConfiguration configuration;

/**
* Used to convert local event from and to remote event.
*/
private final EventConverterManager eventConverterManager;

/**
* Used to inject event coming from network.
*/
private final ObservationManager observationManager;

/**
* Used to set some extra informations about the current event injected to the local
* {@link ObservationManager}.
*/
private final RemoteObservationManagerContext remoteEventManagerContext;

/**
* Used to initialize ExecutionContext for the remote->local thread.
*/
private final Execution execution;

/**
* Used to initialize ExecutionContext for the remote->local thread.
*/
private final ExecutionContextManager executionContextManager;

/**
* Used to lookup the network adapter.
*/
private final BeanFactory beanFactory;

/**
* The network adapter to use to actually send and receive network messages.
*/
private NetworkAdapter networkAdapter;

@Inject
public DefaultRemoteObservationManager(
public IncomingObservationManager(
RemoteObservationManagerConfiguration configuration,
EventConverterManager eventConverterManager,
ObservationManager observationManager,
Expand All @@ -114,36 +72,16 @@ public DefaultRemoteObservationManager(

@PostConstruct
public void initialize() {
var adapter = configuration.getImplementation()
NetworkAdapter adapter = configuration.getImplementation()
.map(name -> beanFactory.getBean(name, NetworkAdapter.class))
.orElse(null);
if (adapter == null) {
LOGGER.info("Remote observation manager is disabled");
return;
}
adapter.start(this::notify);
networkAdapter = adapter;
}

@Override
public void notify(LocalEventData localEvent) {
if (networkAdapter == null) {
throw new IllegalStateException("Remote observation manager is disabled");
}
if (this.remoteEventManagerContext.isRemoteState()) {
return; // the event is a remote event
}
RemoteEventData remoteEvent = this.eventConverterManager.createRemoteEventData(localEvent);
// if remote event data is not filled it mean the message should not be sent to the network
if (remoteEvent != null) {
networkAdapter.send(remoteEvent);
}
if (localEvent.getEvent() instanceof ApplicationStoppedEvent) {
networkAdapter.stop();
}
}

@Override
public void notify(RemoteEventData remoteEvent) {
LocalEventData localEvent = null;
try {
Expand All @@ -169,5 +107,4 @@ private void initEContext() throws ExecutionContextException {
execution.setContext(executionContext);
executionContextManager.initialize(executionContext);
}

}

This file was deleted.

Loading