View Javadoc

1   /*
2    * Copyright (c) 1998-2004 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18  
19  package jgroup.test.multicast;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.io.ObjectInputStream;
24  
25  import jgroup.core.GroupManager;
26  import jgroup.core.JgroupException;
27  import jgroup.core.MemberId;
28  import jgroup.core.MembershipListener;
29  import jgroup.core.View;
30  import jgroup.core.multicast.MulticastListener;
31  
32  /**
33   * Simple multicast/total order test server.
34   *
35   * @author Hein Meling
36   * @since Jgroup 2.2
37   */
38  public class TotalOrderTestReceive
39    implements MulticastListener, MembershipListener
40  {
41  
42    ////////////////////////////////////////////////////////////////////////////////////////////
43    // Static fields
44    ////////////////////////////////////////////////////////////////////////////////////////////
45  
46    /** Protocol name used to distinguish messages from other protocols. */
47    private static final String PROTOCOL_NAME = "Total2";
48  
49  
50    ////////////////////////////////////////////////////////////////////////////////////////////
51    // Constructor
52    ////////////////////////////////////////////////////////////////////////////////////////////
53  
54    private TotalOrderTestReceive()
55      throws JgroupException, IOException
56    {
57      GroupManager gm = GroupManager.getGroupManager(this);
58    }
59  
60  
61    ////////////////////////////////////////////////////////////////////////////////////////////
62    // Main method
63    ////////////////////////////////////////////////////////////////////////////////////////////
64  
65    public static void main(String[] argv)
66      throws Exception
67    {
68      TotalOrderTestReceive totc = new TotalOrderTestReceive();
69    }
70  
71    ////////////////////////////////////////////////////////////////////////////////////////////
72    // Methods from MembershipListener
73    ////////////////////////////////////////////////////////////////////////////////////////////
74  
75    public void viewChange(View view)
76    {
77      System.out.println("View: " + view);
78    }
79  
80    public void prepareChange() { }
81  
82    public void hasLeft() { }
83  
84  
85    ////////////////////////////////////////////////////////////////////////////////////////////
86    // Methods from MulticastListener
87    ////////////////////////////////////////////////////////////////////////////////////////////
88  
89    /**
90     *  Returns a string naming the protocol implemented by this multicast
91     *  listener.
92     */
93    public String getProtocolName() 
94    {
95      return PROTOCOL_NAME;
96    }
97  
98    public Object deliverStream(InputStream stream, MemberId sender, int seqNo)
99    {
100     String s = null;
101     try {
102       ObjectInputStream ios = new ObjectInputStream(stream);
103       s = ios.readUTF();
104     } catch (IOException e) {
105       e.printStackTrace();
106     }
107     System.out.println("TotalOrderTestReceive: deliverStream: " + s);
108     return null;
109   }
110 
111 
112   public Object deliverObject(Object obj, MemberId sender, int seqNo)
113   {
114     System.out.println("MulticastTestServer: deliverObject: " + obj);
115     return null;
116   }
117 
118 } // END MulticastObjectServer