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.openejb.client;
17:
18: import java.io.Externalizable;
19: import java.io.IOException;
20: import java.io.ObjectInput;
21: import java.io.ObjectOutput;
22: import java.net.URI;
23: import java.rmi.RemoteException;
24: import java.util.Arrays;
25:
26: public class ServerMetaData implements Externalizable {
27:
28: private transient URI[] locations;
29: private transient ConnectionFactoryStrategy connectionFactoryStrategy;
30:
31: public ServerMetaData() {
32: }
33:
34: public ServerMetaData(URI... locations) {
35: this .locations = locations;
36: }
37:
38: public void merge(ServerMetaData toMerge) {
39: locations = toMerge.locations;
40: }
41:
42: public URI[] getLocations() {
43: return locations;
44: }
45:
46: public int buildHash() {
47: int locationsHash = 0;
48: for (URI location : locations) {
49: locationsHash += location.hashCode();
50: }
51: return locationsHash;
52: }
53:
54: public Connection connect(Request request) throws RemoteException {
55: ConnectionFactoryStrategy factoryStrategy = getConnectionFactoryStrategy();
56: return factoryStrategy.connect(locations, request);
57: }
58:
59: protected ConnectionFactoryStrategy getConnectionFactoryStrategy() {
60: if (null == connectionFactoryStrategy) {
61: connectionFactoryStrategy = new StickToLastServerConnectionFactoryStrategy();
62: }
63: return connectionFactoryStrategy;
64: }
65:
66: public void readExternal(ObjectInput in) throws IOException,
67: ClassNotFoundException {
68: byte version = in.readByte(); // future use
69:
70: locations = (URI[]) in.readObject();
71: }
72:
73: public void writeExternal(ObjectOutput out) throws IOException {
74: // write out the version of the serialized data for future use
75: out.writeByte(1);
76:
77: out.writeObject(locations);
78: }
79:
80: public String toString() {
81: return Arrays.toString(locations);
82: }
83:
84: }
|