Search in sources :

Example 6 with ISharedObjectActivatedEvent

use of org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent 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 7 with ISharedObjectActivatedEvent

use of org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent in project ecf by eclipse.

the class FeedSharedObject method handleEvent.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.util.IEventHandler#handleEvent(org.eclipse.ecf.core.util.Event)
	 */
public void handleEvent(Event event) {
    trace("handleEvent(" + event + ")");
    if (event instanceof ISharedObjectMessageEvent) {
        ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event;
        handleMessage(e);
    } else if (event instanceof IContainerConnectedEvent) {
        IContainerConnectedEvent e = (IContainerConnectedEvent) event;
        if (e.getTargetID().equals(config.getContext().getLocalContainerID())) {
        // this container joined
        // handleJoined();
        } else if (config.getContext().isGroupManager()) {
            // some other container joined and we're the server
            handleJoined(e.getTargetID());
        }
    } else if (event instanceof IContainerDisconnectedEvent) {
        IContainerDisconnectedEvent e = (IContainerDisconnectedEvent) event;
        // some other container departed -- same as peer deactivation
        if (!e.getTargetID().equals(config.getContext().getLocalContainerID())) {
            handleLeave(e.getTargetID());
        }
    } else if (event instanceof ISharedObjectActivatedEvent) {
    /*
																	 * ISharedObjectActivatedEvent
																	 * e =
																	 * (ISharedObjectActivatedEvent)
																	 * event;
																	 * if(e.getActivatedID().equals(config.getSharedObjectID())) { //
																	 * we're
																	 * being
																	 * activated
																	 * handleActivated(); }
																	 */
    } else if (event instanceof ISharedObjectDeactivatedEvent) {
    /*
																	 * ISharedObjectDeactivatedEvent
																	 * e =
																	 * (ISharedObjectDeactivatedEvent)
																	 * event;
																	 * if(e.getDeactivatedID().equals(config.getSharedObjectID())) { //
																	 * we're
																	 * being
																	 * deactivated
																	 * handleDeactivated(); }
																	 * else
																	 * if(table.contains(e.getDeactivatedID())) { //
																	 * a local
																	 * graph we
																	 * track is
																	 * being
																	 * deactivated
																	 * handleRemoved(e.getDeactivatedID()); }
																	 */
    }
}
Also used : ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) ISharedObjectDeactivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectDeactivatedEvent) IContainerDisconnectedEvent(org.eclipse.ecf.core.events.IContainerDisconnectedEvent) ISharedObjectMessageEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectMessageEvent) IContainerConnectedEvent(org.eclipse.ecf.core.events.IContainerConnectedEvent)

Example 8 with ISharedObjectActivatedEvent

use of org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent 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 9 with ISharedObjectActivatedEvent

use of org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent 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

ISharedObjectActivatedEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent)9 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)5 ISharedObjectDeactivatedEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectDeactivatedEvent)5 IContainerDisconnectedEvent (org.eclipse.ecf.core.events.IContainerDisconnectedEvent)4 ISharedObjectMessageEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectMessageEvent)4 Event (org.eclipse.ecf.core.util.Event)3 IEventProcessor (org.eclipse.ecf.core.util.IEventProcessor)3 ID (org.eclipse.ecf.core.identity.ID)2 IContainerListener (org.eclipse.ecf.core.IContainerListener)1 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)1