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;
17:
18: import java.io.IOException;
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: import javax.management.remote.JMXConnector;
23: import javax.management.remote.JMXConnectorFactory;
24: import javax.management.remote.JMXServiceURL;
25:
26: /**
27: *
28: * @version $Rev$ $Date$
29: */
30: public abstract class AbstractNode implements Node {
31: private final String name;
32:
33: public AbstractNode(String name) {
34: if (null == name) {
35: throw new IllegalArgumentException("name is required");
36: }
37: this .name = name;
38: }
39:
40: public String getName() {
41: return name;
42: }
43:
44: public JMXConnector getJMXConnector() throws IOException {
45: Map<String, Object> environment = new HashMap<String, Object>();
46: environment.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
47: AbstractNode.class.getClassLoader());
48: JMXServiceURL address = new JMXServiceURL(
49: "service:jmx:rmi:///jndi/rmi://" + getHost() + ":"
50: + getPort() + "/JMXConnector");
51: return JMXConnectorFactory.connect(address, environment);
52: }
53:
54: protected abstract String getHost();
55:
56: protected abstract int getPort();
57:
58: @Override
59: public boolean equals(Object obj) {
60: if (!(obj instanceof AbstractNode)) {
61: return false;
62: }
63: AbstractNode other = (AbstractNode) obj;
64: return name.equals(other.name);
65: }
66:
67: @Override
68: public int hashCode() {
69: return name.hashCode();
70: }
71:
72: }
|