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.gm;
20  
21  import jgroup.core.GroupManager;
22  import jgroup.core.JgroupException;
23  import jgroup.core.MemberId;
24  import jgroup.core.MembershipListener;
25  import jgroup.core.MembershipService;
26  import jgroup.core.View;
27  import jgroup.relacs.config.AppConfig;
28  
29  /**
30   *  Jgroup server for measuring the performance of IGMI invocations versus
31   *  message multicasing.
32   *
33   *  @author Hein Meling
34   *  @since Jgroup 1.2
35   */
36  public class RemoteTestServer
37    implements MembershipListener
38  {
39  
40    ////////////////////////////////////////////////////////////////////////////////////////////
41    // Fields (non-shared state)
42    ////////////////////////////////////////////////////////////////////////////////////////////
43  
44    /** Keep the time of the last view change */
45    private long lastViewChange = 0;
46  
47    /** Buffer for storing log output */
48    private StringBuilder buf = new StringBuilder();
49  
50    private RemoteTestService rts;
51  
52    private MemberId myId;
53  
54    private int minRedundancy;
55  
56  
57    ////////////////////////////////////////////////////////////////////////////////////////////
58    // Constructor
59    ////////////////////////////////////////////////////////////////////////////////////////////
60  
61    public RemoteTestServer()
62      throws JgroupException
63    {
64      buf.append("----------------------------------------------------------\n");
65      buf.append("Log time : Number of members : Time since last view change\n");
66  
67      GroupManager gm = GroupManager.getGroupManager(this);
68      rts = (RemoteTestService) gm.getService("RemoteTest");
69      MembershipService pgms = (MembershipService) gm.getService("PGMS");
70      AppConfig thisApp = AppConfig.getApplication(this);
71      minRedundancy = thisApp.getMinimalRedundancy();
72      myId = pgms.getMyIdentifier();
73      pgms.join(thisApp.getGroupId());
74      System.out.println("RemoteTestServer initialized");
75    }
76  
77  
78    ////////////////////////////////////////////////////////////////////////////////////////////
79    // Methods from MembershipListener
80    ////////////////////////////////////////////////////////////////////////////////////////////
81  
82    public void viewChange(View view)
83    {
84      long currentTime = System.currentTimeMillis();
85  
86      buf.append(currentTime);
87      buf.append(" : ");
88      buf.append(view.size());
89      buf.append(" : ");
90      buf.append((lastViewChange != 0) ? (currentTime - lastViewChange) : 0);
91      buf.append("\n");
92      System.out.println(buf.toString());
93  
94      /* Keep the time of this view change */
95      lastViewChange = currentTime;
96  
97      System.out.println("min:" +minRedundancy);
98      System.out.println("myid:" +myId);
99  
100     /*
101      * Activate the measurements when we have reached 'minRedundancy' members.
102      * Note that only one member (member number 'minRedundancy') will actually
103      * be performing invocations.  The other members will only respond to
104      * invocations.
105      */
106     if (view.memberHasPosition(minRedundancy-1, myId)) {
107       rts.activate();
108     }
109 
110     /*
111      * Activate the measurements when we have reached 'minRedundancy' members.
112      * In this scenario all members will start to perform invocations, when
113      * the total number of group members reach 'minRedundancy'.  However, they
114      * will also all be responding to invocations from all the other members.
115      * Thus, response time deteriorates rapidly with growing number of members.
116      */
117 //    if (view.size() >= minRedundancy) {
118 //      rts.activate();
119 //    }
120   }
121 
122   public void hasLeft() { }
123 
124   public void prepareChange() {}
125 
126 
127   ////////////////////////////////////////////////////////////////////////////////////////////
128   // Main method
129   ////////////////////////////////////////////////////////////////////////////////////////////
130 
131   public static void main(String[] argv)
132     throws Exception
133   {
134     RemoteTestServer server = new RemoteTestServer();
135   }
136 
137 } // END RemoteTestServer