Search in sources :

Example 1 with RemoteEventCollection

use of org.apache.jackrabbit.rmi.remote.RemoteEventCollection in project jackrabbit by apache.

the class ServerAdapterFactory method getRemoteEvent.

/**
     * Creates a {@link ServerEventCollection ServerEventCollection} instances.
     * {@inheritDoc}
     */
public RemoteEventCollection getRemoteEvent(long listenerId, EventIterator events) throws RemoteException {
    RemoteEventCollection.RemoteEvent[] remoteEvents;
    if (events != null) {
        List<ServerEventCollection.ServerEvent> eventList = new ArrayList<ServerEventCollection.ServerEvent>();
        while (events.hasNext()) {
            Event event = events.nextEvent();
            eventList.add(new ServerEventCollection.ServerEvent(event, this));
        }
        remoteEvents = eventList.toArray(new RemoteEventCollection.RemoteEvent[eventList.size()]);
    } else {
        // for
        remoteEvents = new RemoteEventCollection.RemoteEvent[0];
    // safety
    }
    return new ServerEventCollection(listenerId, remoteEvents, this);
}
Also used : RemoteEventCollection(org.apache.jackrabbit.rmi.remote.RemoteEventCollection) ArrayList(java.util.ArrayList) Event(javax.jcr.observation.Event)

Example 2 with RemoteEventCollection

use of org.apache.jackrabbit.rmi.remote.RemoteEventCollection in project jackrabbit by apache.

the class ClientEventPoll method run.

//---------- Thread overwrite ---------------------------------------------
/**
     * Checks for remote events and dispatches them to the locally registered
     * event listeners. This is how this method works:
     * <ol>
     * <li>Continue with next step if {@link #terminate()} has not been called
     * yet and the session is still alive.
     * <li>Call the {@link RemoteObservationManager#getNextEvent(long)} method
     * waiting for a specified time (5 seconds).
     * <li>If no event was received in the specified time go back to step #1.
     * <li>Extract the unique listener identifier from the remote event and
     * find it in the list of locally registered event listeners. Go back to
     * step #1 if no such listener exists.
     * <li>Convert the remote event list to an <code>EventIterator</code> and
     * call the <code>EventListener.onEvent()</code> method.
     * <li>Go back to step #1.
     * </ol>
     */
public void run() {
    while (running && session.isLive()) {
        try {
            // ask for an event waiting at most POLL_TIMEOUT milliseconds
            RemoteEventCollection remoteEvent = remote.getNextEvent(POLL_TIMEOUT);
            // poll time out, check running and ask again
            if (remoteEvent == null) {
                continue;
            }
            // extract the listener id from the remote event and find
            // the locally registered event listener
            Long id = new Long(remoteEvent.getListenerId());
            EventListener listener = (EventListener) listenerMap.get(id);
            // silently ignored, running is checked and the server asked again
            if (listener == null) {
                continue;
            }
            // otherwise convert the remote events into an EventIterator
            // and the listener is called
            RemoteEventCollection.RemoteEvent[] remoteEvents = remoteEvent.getEvents();
            EventIterator events = toEvents(remoteEvents);
            try {
                listener.onEvent(events);
            } catch (Exception e) {
                log.error("Unexpected failure of Listener " + listener, e);
            }
        } catch (RemoteException re) {
            log.error("Problem handling event. Looking for next one.", re);
        }
    }
}
Also used : RemoteEventCollection(org.apache.jackrabbit.rmi.remote.RemoteEventCollection) EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator) ArrayEventIterator(org.apache.jackrabbit.rmi.iterator.ArrayEventIterator) RemoteException(java.rmi.RemoteException) RemoteRuntimeException(org.apache.jackrabbit.rmi.client.RemoteRuntimeException) RemoteException(java.rmi.RemoteException) RepositoryException(javax.jcr.RepositoryException) RemoteRepositoryException(org.apache.jackrabbit.rmi.client.RemoteRepositoryException)

Example 3 with RemoteEventCollection

use of org.apache.jackrabbit.rmi.remote.RemoteEventCollection in project jackrabbit by apache.

the class ServerEventListenerProxy method onEvent.

/**
     * Converts the {@link javax.jcr.observation.Event} instances in the given
     * iterator to an instance of {@link RemoteEventCollection} for them to be dispatched
     * to the client-side event listener.
     *
     * @param events The {@link javax.jcr.observation.Event Events} to be
     *      dispatched.
     */
public void onEvent(EventIterator events) {
    try {
        RemoteEventCollection remoteEvent = factory.getRemoteEvent(listenerId, events);
        queue.put(remoteEvent);
    } catch (RemoteException re) {
        Throwable t = (re.getCause() == null) ? re : re.getCause();
        log.error("Problem creating remote event for " + listenerId, t);
    }
}
Also used : RemoteEventCollection(org.apache.jackrabbit.rmi.remote.RemoteEventCollection) RemoteException(java.rmi.RemoteException)

Aggregations

RemoteEventCollection (org.apache.jackrabbit.rmi.remote.RemoteEventCollection)3 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)1 RepositoryException (javax.jcr.RepositoryException)1 Event (javax.jcr.observation.Event)1 EventIterator (javax.jcr.observation.EventIterator)1 EventListener (javax.jcr.observation.EventListener)1 RemoteRepositoryException (org.apache.jackrabbit.rmi.client.RemoteRepositoryException)1 RemoteRuntimeException (org.apache.jackrabbit.rmi.client.RemoteRuntimeException)1 ArrayEventIterator (org.apache.jackrabbit.rmi.iterator.ArrayEventIterator)1