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.apache.geronimo.clustering.AbstractNode;
19: import org.codehaus.wadi.group.Peer;
20:
21: /**
22: *
23: * @version $Rev$ $Date$
24: */
25: public class RemoteNode extends AbstractNode {
26: private static final String ADAPTOR_KEY = "ADAPTOR_KEY";
27:
28: public static RemoteNode retrieveOptionalAdaptor(Peer peer) {
29: return (RemoteNode) peer.getLocalStateMap().get(ADAPTOR_KEY);
30: }
31:
32: public static RemoteNode retrieveAdaptor(Peer peer) {
33: RemoteNode node = (RemoteNode) peer.getLocalStateMap().get(
34: ADAPTOR_KEY);
35: if (null == node) {
36: throw new IllegalStateException("No registered adaptor");
37: }
38: return node;
39: }
40:
41: private final Peer peer;
42: private final NodeService nodeService;
43: private NodeConnectionInfo connectionInfo;
44:
45: public RemoteNode(Peer peer, NodeService nodeService) {
46: super (peer.getName());
47: if (null == nodeService) {
48: throw new IllegalArgumentException(
49: "nodeService is required");
50: }
51: this .peer = peer;
52: this .nodeService = nodeService;
53:
54: peer.getLocalStateMap().put(ADAPTOR_KEY, this );
55: }
56:
57: public Peer getPeer() {
58: return peer;
59: }
60:
61: @Override
62: protected String getHost() {
63: if (null == connectionInfo) {
64: connectionInfo = nodeService.getConnectionInfo();
65: }
66: return connectionInfo.getHost();
67: }
68:
69: @Override
70: protected int getPort() {
71: if (null == connectionInfo) {
72: connectionInfo = nodeService.getConnectionInfo();
73: }
74: return connectionInfo.getPort();
75: }
76:
77: }
|