Search in sources :

Example 1 with Event

use of org.eclipse.ecf.core.util.Event in project ecf by eclipse.

the class TestSharedObject method initialize.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#initialize()
	 */
protected void initialize() throws SharedObjectInitException {
    super.initialize();
    if (isPrimary()) {
        // If primary, then add an event processor that handles activated
        // event by replicating to all current remote containers
        addEventProcessor(new IEventProcessor() {

            public boolean processEvent(Event event) {
                if (event instanceof ISharedObjectActivatedEvent) {
                    ISharedObjectActivatedEvent ae = (ISharedObjectActivatedEvent) event;
                    if (ae.getActivatedID().equals(getID()) && isConnected()) {
                        TestSharedObject.this.replicateToRemoteContainers(null);
                    }
                }
                return false;
            }
        });
        System.out.println("Primary(" + getContext().getLocalContainerID() + ") says Hello " + name);
    } else {
        // This is a replica, so initialize the name from property
        name = (String) getConfig().getProperties().get(NAME_PROPERTY);
        System.out.println("Replica(" + getContext().getLocalContainerID() + ") says Hello " + name);
    }
}
Also used : IEventProcessor(org.eclipse.ecf.core.util.IEventProcessor) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) Event(org.eclipse.ecf.core.util.Event)

Example 2 with Event

use of org.eclipse.ecf.core.util.Event in project ecf by eclipse.

the class MyChannel method initialize.

protected void initialize() throws SharedObjectInitException {
    super.initialize();
    // Add event processor that responds to IContainerConnectedEvent messages
    addEventProcessor(new IEventProcessor() {

        public boolean processEvent(Event event) {
            // If event is IContainerConnectedEvent
            if (event instanceof IContainerConnectedEvent) {
                IContainerConnectedEvent ccevent = (IContainerConnectedEvent) event;
                // Check to make sure it's a client...not the groupID
                if (!ccevent.getTargetID().equals(getConnectedID()))
                    sendHelloMessage();
            }
            return false;
        }
    });
}
Also used : IEventProcessor(org.eclipse.ecf.core.util.IEventProcessor) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent) Event(org.eclipse.ecf.core.util.Event) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent)

Example 3 with Event

use of org.eclipse.ecf.core.util.Event in project ecf by eclipse.

the class OptimisticSharedObject method initialize.

protected void initialize() throws SharedObjectInitException {
    super.initialize();
    Trace.entering(Activator.PLUGIN_ID, SharedObjectDebugOptions.METHODS_ENTERING, OptimisticSharedObject.class, // $NON-NLS-1$
    "initialize");
    addEventProcessor(new IEventProcessor() {

        public boolean processEvent(Event event) {
            if (event instanceof ISharedObjectActivatedEvent) {
                // then replicate to all remotes
                if (isPrimary() && isConnected()) {
                    OptimisticSharedObject.this.replicateToRemoteContainers(null);
                }
            } else if (event instanceof IContainerConnectedEvent) {
                // then replicate to the newly arrived container
                if (isPrimary()) {
                    ID targetID = ((IContainerConnectedEvent) event).getTargetID();
                    OptimisticSharedObject.this.replicateToRemoteContainers(new ID[] { targetID });
                }
            }
            return false;
        }
    });
    Trace.exiting(Activator.PLUGIN_ID, SharedObjectDebugOptions.METHODS_EXITING, OptimisticSharedObject.class, // $NON-NLS-1$
    "initialize");
}
Also used : IEventProcessor(org.eclipse.ecf.core.util.IEventProcessor) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent) Event(org.eclipse.ecf.core.util.Event) ID(org.eclipse.ecf.core.identity.ID) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent)

Example 4 with Event

use of org.eclipse.ecf.core.util.Event in project ecf by eclipse.

the class TestMessagingSharedObject method initialize.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#initialize()
	 */
protected void initialize() throws SharedObjectInitException {
    super.initialize();
    if (isPrimary()) {
        // If primary, then add an event processor that handles activated
        // event by replicating to all current remote containers
        addEventProcessor(new IEventProcessor() {

            public boolean processEvent(Event event) {
                if (event instanceof ISharedObjectActivatedEvent) {
                    ISharedObjectActivatedEvent ae = (ISharedObjectActivatedEvent) event;
                    if (ae.getActivatedID().equals(getID()) && isConnected()) {
                        TestMessagingSharedObject.this.replicateToRemoteContainers(null);
                    }
                }
                return false;
            }
        });
        System.out.println("Primary(" + getContext().getLocalContainerID() + ") says Hello " + name);
    } else {
        // This is a replica, so initialize the name from property
        name = (String) getConfig().getProperties().get(NAME_PROPERTY);
        System.out.println("Replica(" + getContext().getLocalContainerID() + ") says Hello " + name);
    }
}
Also used : IEventProcessor(org.eclipse.ecf.core.util.IEventProcessor) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) Event(org.eclipse.ecf.core.util.Event)

Aggregations

Event (org.eclipse.ecf.core.util.Event)4 IEventProcessor (org.eclipse.ecf.core.util.IEventProcessor)4 ISharedObjectActivatedEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent)3 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)2 ID (org.eclipse.ecf.core.identity.ID)1