01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.clustering.wadi;
17:
18: import org.codehaus.wadi.group.Dispatcher;
19: import org.codehaus.wadi.group.Peer;
20: import org.codehaus.wadi.servicespace.InvocationMetaData;
21: import org.codehaus.wadi.servicespace.ServiceAlreadyRegisteredException;
22: import org.codehaus.wadi.servicespace.ServiceProxyFactory;
23: import org.codehaus.wadi.servicespace.ServiceRegistry;
24: import org.codehaus.wadi.servicespace.ServiceSpace;
25: import org.codehaus.wadi.servicespace.admin.AdminServiceSpace;
26: import org.codehaus.wadi.servicespace.admin.AdminServiceSpaceHelper;
27:
28: /**
29: *
30: * @version $Rev$ $Date$
31: */
32: public class NodeServiceHelper {
33: private final ServiceSpace serviceSpace;
34:
35: public NodeServiceHelper(Dispatcher dispatcher) {
36: if (null == dispatcher) {
37: throw new IllegalArgumentException("dispatcher is required");
38: }
39: this .serviceSpace = getAdminServiceSpace(dispatcher);
40: }
41:
42: public NodeServiceHelper(ServiceSpace serviceSpace) {
43: if (null == serviceSpace) {
44: throw new IllegalArgumentException(
45: "serviceSpace is required");
46: }
47: this .serviceSpace = serviceSpace;
48: }
49:
50: public void registerNodeService(NodeService nodeService) {
51: ServiceRegistry serviceRegistry = serviceSpace
52: .getServiceRegistry();
53: try {
54: serviceRegistry.register(NodeService.SERVICE_NAME,
55: nodeService);
56: } catch (ServiceAlreadyRegisteredException e) {
57: throw new IllegalStateException(
58: "NodeService already registered.", e);
59: }
60: }
61:
62: public NodeService getNodeServiceProxy(Peer peer) {
63: ServiceProxyFactory proxyFactory = serviceSpace
64: .getServiceProxyFactory(NodeService.SERVICE_NAME,
65: new Class[] { NodeService.class });
66: InvocationMetaData invocationMetaData = proxyFactory
67: .getInvocationMetaData();
68: invocationMetaData.setTargets(new Peer[] { peer });
69: return (NodeService) proxyFactory.getProxy();
70: }
71:
72: protected ServiceSpace getAdminServiceSpace(Dispatcher dispatcher) {
73: AdminServiceSpaceHelper helper = new AdminServiceSpaceHelper();
74: AdminServiceSpace adminServiceSpace = helper
75: .getAdminServiceSpace(dispatcher);
76: return adminServiceSpace;
77: }
78:
79: }
|