KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > cluster > tcp > IDataSenderFactory


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 import org.apache.catalina.cluster.Member;
19 import java.net.InetAddress JavaDoc;
20
21 /**
22  * @author Peter Rossbach
23  * @version 1.0
24  * @since 5.5.7
25  */

26 public class IDataSenderFactory {
27     private IDataSenderFactory() {
28     }
29     public static final String JavaDoc SYNC_MODE="synchronous";
30     public static final String JavaDoc ASYNC_MODE="asynchronous";
31     public static final String JavaDoc POOLED_SYNC_MODE="pooled";
32     public static final String JavaDoc FAST_ASYNC_QUEUE_MODE="fastasyncqueue";
33
34     public synchronized static IDataSender getIDataSender(String JavaDoc mode, Member mbr)
35     throws java.io.IOException JavaDoc {
36         if (SYNC_MODE.equals(mode) )
37             return new SocketSender(InetAddress.getByName(mbr.getHost()),mbr.getPort());
38         else if ( ASYNC_MODE.equals(mode) )
39             return new AsyncSocketSender(InetAddress.getByName(mbr.getHost()),mbr.getPort());
40         else if ( FAST_ASYNC_QUEUE_MODE.equals(mode) )
41             return new FastAsyncSocketSender(InetAddress.getByName(mbr.getHost()),mbr.getPort());
42         else if (POOLED_SYNC_MODE.equals(mode) )
43             return new PooledSocketSender(InetAddress.getByName(mbr.getHost()),mbr.getPort());
44         else
45             throw new java.io.IOException JavaDoc("Invalid replication mode="+mode);
46     }
47
48     public static String JavaDoc validateMode(String JavaDoc mode) {
49         if (SYNC_MODE.equals(mode) ||
50             ASYNC_MODE.equals(mode) ||
51             FAST_ASYNC_QUEUE_MODE.equals(mode) ||
52             POOLED_SYNC_MODE.equals(mode) ) {
53             return null;
54         } else {
55             return "Replication mode has to be '"+SYNC_MODE+"', '" + FAST_ASYNC_QUEUE_MODE +"', '"+ASYNC_MODE+"' or '"+POOLED_SYNC_MODE+"'";
56         }
57     }
58
59
60 }
61
Popular Tags