01: package org.jgroups;
02:
03: import java.io.InputStream;
04:
05: /**
06: *
07: * Represents an event returned by <code>channel.receive()</code>, as requested by
08: * <code>channel.getState()</code> previously.
09: *
10: * <p>
11: *
12: * Allows applications using a channel in a pull mode to receive a state from
13: * another channel instance providing state. Channels have to be configured with
14: * <code>STREAMING_STATE_TRANSFER</code> protocol rather than the default
15: * <code>STATE_TRANSFER</code> protocol in order to receive this event.
16: *
17: * <p>
18: *
19: * The following code demonstrate how to pull events from a channel, processing
20: * <code>StreamingSetStateEvent</code> and retrieving hypothetical state in the
21: * form of LinkedList from event's <code>InputStream</code> reference.
22: *
23: * <blockquote><pre>
24: * Object obj=channel.receive(0);
25: * if(obj instanceof StreamingSetStateEvent) {
26: * StreamingSetStateEvent evt=(StreamingSetStateEvent)obj;
27: * ObjectInputStream ois = null;
28: * try {
29: * ois = new ObjectInputStream(evt.getArg());
30: * state = (LinkedList)ois.readObject();
31: * } catch (Exception e) {}
32: * finally
33: * {
34: * try {
35: * ois.close();
36: * } catch (IOException e) {
37: * System.err.println(e);
38: * }
39: * }
40: * }
41: * </pre></blockquote>
42: *
43: *
44: * @author Vladimir Blagojevic
45: * @see org.jgroups.JChannel#getState(Address, long)
46: * @see org.jgroups.StreamingMessageListener#setState(InputStream)
47: * @since 2.4
48: *
49: */
50: public class StreamingSetStateEvent {
51:
52: InputStream is;
53: String state_id;
54:
55: public StreamingSetStateEvent(InputStream is, String state_id) {
56: super ();
57: this .is = is;
58: this .state_id = state_id;
59: }
60:
61: /**
62: * Returns InputStream used for reading of a state.
63: *
64: * @return the InputStream
65: */
66: public InputStream getArg() {
67: return is;
68: }
69:
70: /**
71: * Returns id of the partial state if partial state was requested.
72: * If full state transfer was requested this method will return null.
73: *
74: * @see JChannel#getState(Address, long)
75: * @see JChannel#getState(Address, String, long)
76: * @return partial state id
77: */
78: public String getStateId() {
79: return state_id;
80: }
81:
82: }
|