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.arm;
20  
21  import java.rmi.RemoteException;
22  
23  import jgroup.core.ConfigManager;
24  import jgroup.core.GroupManager;
25  import jgroup.core.JgroupException;
26  import jgroup.core.protocols.Anycast;
27  import jgroup.core.protocols.Multicast;
28  import jgroup.test.performance.RemoteShutdown;
29  import jgroup.test.performance.SpeedTest;
30  import jgroup.util.Network;
31  import jgroup.util.log.Eventlogger;
32  import jgroup.util.log.ReplicaEvent;
33  import static jgroup.util.log.ReplicaEvent.Type.Initialized;
34  
35  /**
36   *  Jgroup server for measuring the performance of GMI invocations and
37   *  server recovery time.
38   *
39   *  @author Hein Meling
40   *  @since Jgroup 1.2
41   */
42  public class ReplicatedServer
43    implements SpeedTest, RemoteShutdown
44  {
45  
46    ////////////////////////////////////////////////////////////////////////////////////////////
47    // Fields (non-shared state)
48    ////////////////////////////////////////////////////////////////////////////////////////////
49  
50    /** The local host name of the server replying to client requests. */
51    private static final String localHost = Network.getLocalMachineName();
52  
53  
54    ////////////////////////////////////////////////////////////////////////////////////////////
55    // Constructor
56    ////////////////////////////////////////////////////////////////////////////////////////////
57  
58    public ReplicatedServer()
59      throws JgroupException
60    {
61      ConfigManager.init();
62      GroupManager gm = GroupManager.getGroupManager(this);
63      if (Eventlogger.ENABLED)
64        Eventlogger.logEventFlush(new ReplicaEvent(Initialized, gm.getGroupId()));
65      System.out.println("ReplicatedServer initialized");
66    }
67  
68  
69    ////////////////////////////////////////////////////////////////////////////////////////////
70    // Methods from SpeedTest
71    ////////////////////////////////////////////////////////////////////////////////////////////
72  
73    @Multicast public void mtest()
74      throws RemoteException
75    {
76    }
77  
78    private int cnt = 0;
79  
80  
81    @Multicast public byte[] mtest(byte[] x)
82      throws RemoteException
83    {
84  //    System.out.print("+");
85  //    if ((cnt % 20) == 0) {
86  //      System.out.println(cnt);
87  //    }
88  //    cnt++;
89      return x;
90    }
91  
92    @Multicast public void vmtest(byte[] x)
93      throws RemoteException
94    {
95      System.out.print("+");
96      if ((cnt % 20) == 0) {
97        System.out.println(cnt);
98      }
99      cnt++;
100   }
101 
102   @Multicast public String mtest(String x)
103     throws RemoteException
104   {
105     System.out.println(x);
106     return x;
107   }
108 
109   @Anycast public void test()
110     throws RemoteException
111   {
112   }
113 
114   @Anycast public byte[] test(byte[] x)
115     throws RemoteException
116   {
117 //    cnt++;
118 //    if (Debug.MEASURE && cnt % 5 == 0)
119 //      Debug.logEvent("cnt " + cnt, "");
120     return x;
121   }
122 
123   @Anycast public String test(String x)
124     throws RemoteException
125   {
126     return localHost + ": " + x;
127   }
128 
129 
130   ////////////////////////////////////////////////////////////////////////////////////////////
131   // Methods from RemoteShutdown
132   ////////////////////////////////////////////////////////////////////////////////////////////
133 
134   @Multicast public void preShutdown()
135     throws RemoteException
136   {
137     if (Eventlogger.ENABLED) {
138       Eventlogger.logEventFlush("PreShutdown localhost: " + localHost);
139     }
140   }
141 
142   @Anycast public void shutdown(final int delay)
143     throws RemoteException
144   {
145     new Thread() {
146       public void run() {
147         System.out.println("I'm shuting down in " + delay + " milliseconds.");
148         if (delay > 0) {
149           try { sleep(delay); } catch (InterruptedException e) { }
150         }
151         System.exit(0);
152       }
153     }.start();
154   }
155 
156 
157   ////////////////////////////////////////////////////////////////////////////////////////////
158   // Main method
159   ////////////////////////////////////////////////////////////////////////////////////////////
160 
161   public static void main(String[] argv)
162     throws Exception
163   {
164     ReplicatedServer server = new ReplicatedServer();
165   }
166 
167 } // END ReplicatedServer