01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.catalina.cluster.tcp;
18:
19: import org.apache.catalina.cluster.Member;
20: import java.net.InetAddress;
21:
22: public class IDataSenderFactory {
23: private IDataSenderFactory() {
24: }
25:
26: public static final String SYNC_MODE = "synchronous";
27: public static final String ASYNC_MODE = "asynchronous";
28: public static final String POOLED_SYNC_MODE = "pooled";
29:
30: public synchronized static IDataSender getIDataSender(String mode,
31: Member mbr) throws java.io.IOException {
32: if (SYNC_MODE.equals(mode))
33: return new SocketSender(InetAddress
34: .getByName(mbr.getHost()), mbr.getPort());
35: else if (ASYNC_MODE.equals(mode))
36: return new AsyncSocketSender(InetAddress.getByName(mbr
37: .getHost()), mbr.getPort());
38: if (POOLED_SYNC_MODE.equals(mode))
39: return new PooledSocketSender(InetAddress.getByName(mbr
40: .getHost()), mbr.getPort());
41: else
42: throw new java.io.IOException("Invalid replication mode="
43: + mode);
44: }
45:
46: public static String validateMode(String mode) {
47: if (SYNC_MODE.equals(mode) || ASYNC_MODE.equals(mode)
48: || POOLED_SYNC_MODE.equals(mode)) {
49: return null;
50: } else {
51: return "Replication mode has to be '" + SYNC_MODE + "', '"
52: + ASYNC_MODE + "' or '" + POOLED_SYNC_MODE + "'";
53: }
54: }
55:
56: }
|