KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > StreamingSetStateEvent


1 package org.jgroups;
2 import java.io.InputStream JavaDoc;
3 /**
4  *
5  * Represents an event returned by <code>channel.receive()</code>, as requested by
6  * <code>channel.getState()</code> previously.
7  *
8  * <p>
9  *
10  * Allows applications using a channel in a pull mode to receive a state from
11  * another channel instance providing state. Channels have to be configured with
12  * <code>STREAMING_STATE_TRANSFER</code> protocol rather than the default
13  * <code>STATE_TRANSFER</code> protocol in order to receive this event.
14  *
15  * <p>
16  *
17  * The following code demonstrate how to pull events from a channel, processing
18  * <code>StreamingSetStateEvent</code> and retrieving hypothetical state in the
19  * form of LinkedList from event's <code>InputStream</code> reference.
20  *
21  * <blockquote><pre>
22  * Object obj=channel.receive(0);
23  * if(obj instanceof StreamingSetStateEvent) {
24  * StreamingSetStateEvent evt=(StreamingSetStateEvent)obj;
25  * ObjectInputStream ois = null;
26  * try {
27  * ois = new ObjectInputStream(evt.getArg());
28  * state = (LinkedList)ois.readObject();
29  * } catch (Exception e) {}
30  * finally
31  * {
32  * try {
33  * ois.close();
34  * } catch (IOException e) {
35  * System.err.println(e);
36  * }
37  * }
38  * }
39  * </pre></blockquote>
40  *
41  *
42  * @author Vladimir Blagojevic
43  * @see org.jgroups.JChannel#getState(Address, long)
44  * @see org.jgroups.StreamingMessageListener#setState(InputStream)
45  * @since 2.4
46  *
47  */

48 public class StreamingSetStateEvent {
49
50     InputStream JavaDoc is;
51     String JavaDoc state_id;
52     
53     public StreamingSetStateEvent(InputStream JavaDoc is,String JavaDoc state_id) {
54         super();
55         this.is=is;
56         this.state_id=state_id;
57     }
58     
59     /**
60      * Returns InputStream used for reading of a state.
61      *
62      * @return the InputStream
63      */

64     public InputStream JavaDoc getArg()
65     {
66         return is;
67     }
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 JavaDoc getStateId()
79     {
80         return state_id;
81     }
82
83 }
84
Popular Tags