View Javadoc

1   /*
2    * Copyright (c) 1998-2002 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.performance;
20  
21  import java.rmi.RemoteException;
22  
23  import jgroup.core.GroupManager;
24  import jgroup.core.IID;
25  import jgroup.core.MemberId;
26  import jgroup.core.MembershipListener;
27  import jgroup.core.MembershipService;
28  import jgroup.core.View;
29  import jgroup.core.registry.RegistryService;
30  import jgroup.util.Abort;
31  
32  /**
33   *  Jgroup server for measuring the performance of GMI invocations.
34   *
35   *  @author Alberto Montresor
36   *  @since Jgroup 1.1
37   */
38  public class SpeedTestServer
39    implements SpeedTest, MembershipListener
40  {
41  
42    private static int counter = 0;
43    
44    ////////////////////////////////////////////////////////////////////////////////////////////
45    // Main
46    ////////////////////////////////////////////////////////////////////////////////////////////
47  
48    public static void main(String[] argv)
49      throws Exception
50    {
51      SpeedTestServer server = new SpeedTestServer();
52      server.start();
53    }
54  
55    ////////////////////////////////////////////////////////////////////////////////////////////
56    // Fields
57    ////////////////////////////////////////////////////////////////////////////////////////////
58  
59    private MembershipService membershipService;
60    private IID registration;
61  
62    
63    ////////////////////////////////////////////////////////////////////////////////////////////
64    // Constructor
65    ////////////////////////////////////////////////////////////////////////////////////////////
66  
67    public SpeedTestServer()
68    {
69    }
70  
71    ////////////////////////////////////////////////////////////////////////////////////////////
72    // Methods from Server
73    ////////////////////////////////////////////////////////////////////////////////////////////
74  
75  
76    public void start()
77      throws Exception
78    {
79      GroupManager gm = GroupManager.getGroupManager(this);
80      membershipService = (MembershipService) gm.getService(MembershipService.class);
81      RegistryService registryService = (RegistryService) gm.getService(RegistryService.class);
82      membershipService.join(101);
83      registration = registryService.bind("Jgroup/SpeedTest", this);
84      System.out.println("SpeedTestServer registered");
85    }
86  
87  
88  
89  
90    ////////////////////////////////////////////////////////////////////////////////////////////
91    // Methods from SpeedTest
92    ////////////////////////////////////////////////////////////////////////////////////////////
93  
94    public void mtest()
95      throws RemoteException
96    {
97      counter++;
98      System.out.print("+");
99      if (counter % 20 == 0)
100       System.out.println("");
101   }
102 
103   public byte[] mtest(byte[] x)
104     throws RemoteException
105   {
106     counter++;
107     if (counter % 20 == 0)
108       System.out.println(counter);
109     return x;
110   }
111 
112   public void vmtest(byte[] x)
113     throws RemoteException
114   {
115     counter++;
116     System.out.print("*");
117     if (counter % 20 == 0)
118       System.out.println("");
119   }
120 
121   public String mtest(String x)
122     throws RemoteException
123   {
124     counter++;
125     System.out.print("+");
126     if (counter % 20 == 0)
127       System.out.println("");
128     return x;
129   }
130 
131   public void test()
132     throws RemoteException
133   {
134     counter++;
135     System.out.print("+");
136     if (counter % 20 == 0)
137       System.out.println("");
138   }
139 
140   public byte[] test(byte[] x)
141     throws RemoteException
142   {
143     counter++;
144     System.out.print("+");
145     if (counter % 20 == 0)
146       System.out.println("");
147     return x;
148   }
149 
150   public String test(String x)
151     throws RemoteException
152   {
153     counter++;
154     System.out.print("+");
155     if (counter % 20 == 0)
156       System.out.println("");
157     return x;
158   }
159 
160   /**
161   * Shut down the server
162    */
163   public void shutdown()
164     throws RemoteException
165   {
166     new Thread() {
167       public void run() {
168         try {
169           sleep(3000);
170         } catch (InterruptedException e) {
171         }
172         Abort.exit(0);
173       }
174     }.start();
175   }
176 
177   ////////////////////////////////////////////////////////////////////////////////////////////
178   // Methods from MembershipListener
179   ////////////////////////////////////////////////////////////////////////////////////////////
180 
181   public void viewChange(View v)
182   {
183     System.out.println("- New View ------------------------");
184     MemberId[] adds = v.getMembers();
185     for (int i=0; i < adds.length ; i++)
186       System.out.println(adds[i]);
187     System.out.println("-----------------------------------");
188   }
189 
190   public void hasLeft()
191   {
192   }
193 
194   public void prepareChange()
195   {
196   }
197 
198 } // END SpeedTestServer
199