KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > drm > MockHAPartition


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.cluster.drm;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import org.jboss.ha.framework.interfaces.ClusterNode;
28 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
29 import org.jboss.ha.framework.interfaces.DistributedState;
30 import org.jboss.ha.framework.interfaces.HAPartition;
31
32 /**
33  * Mock implementation of HAPartition intended to support unit testing
34  * of DistributedReplicantManagerImpl without the need for an underlying
35  * JChannel.
36  *
37  * @author <a HREF="brian.stansberry@jboss.com">Brian Stansberry</a>
38  * @version $Id: MockHAPartition.java 58594 2006-11-18 11:49:07Z bstansberry@jboss.com $
39  */

40 public class MockHAPartition implements HAPartition
41 {
42    public static final String JavaDoc PARTITION_NAME = "MockPartition";
43    
44    private DistributedReplicantManager drm;
45    private Vector JavaDoc currentNodes;
46    private ClusterNode localAddress;
47    private ArrayList JavaDoc remoteReplicants;
48    
49    public MockHAPartition(ClusterNode localAddress)
50    {
51       this.localAddress = localAddress;
52    }
53    // ------------------------------------------------------------ HAPartition
54

55    public String JavaDoc getNodeName()
56    {
57       return localAddress.getName();
58    }
59
60    public String JavaDoc getPartitionName()
61    {
62       return PARTITION_NAME;
63    }
64
65    public DistributedReplicantManager getDistributedReplicantManager()
66    {
67       return drm;
68    }
69
70    public DistributedState getDistributedStateService()
71    {
72
73       throw new UnsupportedOperationException JavaDoc("not implemented");
74    }
75
76    public void registerRPCHandler(String JavaDoc serviceName, Object JavaDoc handler)
77    {
78       if (handler instanceof DistributedReplicantManager)
79          drm = (DistributedReplicantManager) handler;
80       else
81          throw new UnsupportedOperationException JavaDoc("not implemented");
82    }
83
84    public void unregisterRPCHandler(String JavaDoc serviceName, Object JavaDoc subscriber)
85    {
86       if (subscriber == drm)
87          drm = null;
88       else
89          throw new UnsupportedOperationException JavaDoc("not implemented");
90    }
91
92    public ArrayList JavaDoc callMethodOnCluster(String JavaDoc serviceName, String JavaDoc methodName, Object JavaDoc[] args, Class JavaDoc[] types,
93          boolean excludeSelf) throws Exception JavaDoc
94    {
95       if (excludeSelf)
96       {
97          if ("_add".equals(methodName))
98          {
99             // no-op -- there is no cluster
100
return null;
101          }
102          else if ("lookupLocalReplicants".equals(methodName) && args.length == 0)
103          {
104             return remoteReplicants;
105          }
106       }
107       // TODO Implement lookupLocalReplicants for DRM SERVICE_NAME
108

109       throw new UnsupportedOperationException JavaDoc("not implemented");
110    }
111
112    public ArrayList JavaDoc callMethodOnCluster(String JavaDoc serviceName, String JavaDoc methodName, Object JavaDoc[] args, boolean excludeSelf)
113          throws Exception JavaDoc
114    {
115
116       throw new UnsupportedOperationException JavaDoc("not implemented");
117    }
118
119    public void callAsynchMethodOnCluster(String JavaDoc serviceName, String JavaDoc methodName, Object JavaDoc[] args, Class JavaDoc[] types,
120          boolean excludeSelf) throws Exception JavaDoc
121    {
122       if (excludeSelf && "_remove".equals(methodName))
123       {
124          // no-op -- there is no cluster
125
return;
126       }
127
128       throw new UnsupportedOperationException JavaDoc("not implemented");
129    }
130
131    public void callAsynchMethodOnCluster(String JavaDoc serviceName, String JavaDoc methodName, Object JavaDoc[] args, boolean excludeSelf)
132          throws Exception JavaDoc
133    {
134       throw new UnsupportedOperationException JavaDoc("not implemented");
135    }
136
137    public ArrayList JavaDoc callMethodOnCoordinatorNode(String JavaDoc serviceName, String JavaDoc methodName, Object JavaDoc[] args, Class JavaDoc[] types,
138          boolean excludeSelf) throws Exception JavaDoc
139    {
140       throw new UnsupportedOperationException JavaDoc("not implemented");
141    }
142
143    public void subscribeToStateTransferEvents(String JavaDoc serviceName, HAPartitionStateTransfer subscriber)
144    {
145       // no-op. at this point the test fixture directly passes state
146
// to the target DRM
147
}
148
149    public void unsubscribeFromStateTransferEvents(String JavaDoc serviceName, HAPartitionStateTransfer subscriber)
150    {
151       // no-op. at this point the test fixture directly passes state
152
// to the target DRM
153
}
154
155    public void registerMembershipListener(HAMembershipListener listener)
156    {
157       // no-op. at this point the test fixture directly passes membership
158
// changes to the target DRM
159
}
160
161    public void unregisterMembershipListener(HAMembershipListener listener)
162    {
163       // no-op. at this point the test fixture directly passes membership
164
// changes to the target DRM
165
}
166    
167    public boolean getAllowSynchronousMembershipNotifications()
168    {
169       return false;
170    }
171    
172    public void setAllowSynchronousMembershipNotifications(boolean allowSync)
173    {
174       // no-op
175
}
176
177    public long getCurrentViewId()
178    {
179
180       throw new UnsupportedOperationException JavaDoc("not implemented");
181    }
182
183    public Vector JavaDoc getCurrentView()
184    {
185       Vector JavaDoc result = new Vector JavaDoc();
186       for (int i = 0; i < currentNodes.size(); i++)
187          result.add(((ClusterNode) currentNodes.elementAt(i)).getName());
188          
189       return result;
190    }
191
192    public ClusterNode[] getClusterNodes()
193    {
194       ClusterNode[] result = new ClusterNode[currentNodes.size()];
195       return (ClusterNode[]) currentNodes.toArray(result);
196    }
197
198    public ClusterNode getClusterNode()
199    {
200       return localAddress;
201    }
202    
203    // --------------------------------------------------------- Public Methods
204

205    public void setCurrentViewClusterNodes(Vector JavaDoc nodes)
206    {
207       this.currentNodes = nodes;
208    }
209    
210    public void setRemoteReplicants(ArrayList JavaDoc remoteReplicants)
211    {
212       this.remoteReplicants = remoteReplicants;
213    }
214
215 }
216
Popular Tags