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