Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c23f573c6d11488aadb3a5214275c84ec22e345d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.eclipse.ecf.tutorial.datashare;

import org.eclipse.ecf.core.events.IContainerConnectedEvent;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.sharedobject.ISharedObjectTransactionConfig;
import org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription;
import org.eclipse.ecf.core.sharedobject.SharedObjectInitException;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.core.util.Event;
import org.eclipse.ecf.core.util.IEventProcessor;
import org.eclipse.ecf.datashare.IChannelListener;
import org.eclipse.ecf.provider.datashare.BaseChannel;

public class MyChannel extends BaseChannel {
	
	public MyChannel() {
		super();
	}

	public MyChannel(ISharedObjectTransactionConfig config, IChannelListener listener) {
		super(config, listener);
	}

	protected ReplicaSharedObjectDescription getReplicaDescription(ID targetContainerID) {
		return null;
	}

	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(getGroupID())) sendHelloMessage();
				}
				return false;
			}});
	}
	
	protected void sendHelloMessage() {
		try {
			// send message
			this.sendMessage(("hello from "+getHomeContainerID().getName()).getBytes());
		} catch (ECFException e) {
			e.printStackTrace();
		}
	}
}

Back to the top