1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * 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 */
17
18 package org.apache.catalina.tribes.transport;
19
20 import org.apache.catalina.tribes.ChannelException;
21 import org.apache.catalina.tribes.ChannelMessage;
22 import org.apache.catalina.tribes.ChannelSender;
23 import org.apache.catalina.tribes.Member;
24 import org.apache.catalina.tribes.util.StringManager;
25 import org.apache.catalina.tribes.transport.nio.PooledParallelSender;
26
27 /**
28 * Transmit message to other cluster members
29 * Actual senders are created based on the replicationMode
30 * type
31 *
32 * @author Filip Hanik
33 * @version $Revision: 532800 $ $Date: 2007-04-26 18:52:29 +0200 (jeu., 26 avr. 2007) $
34 */
35 public class ReplicationTransmitter implements ChannelSender {
36 private static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(ReplicationTransmitter.class);
37
38 /**
39 * The descriptive information about this implementation.
40 */
41 private static final String info = "ReplicationTransmitter/3.0";
42
43 /**
44 * The string manager for this package.
45 */
46 protected StringManager sm = StringManager.getManager(Constants.Package);
47
48
49
50 public ReplicationTransmitter() {
51 }
52
53 private MultiPointSender transport = new PooledParallelSender();
54
55 /**
56 * Return descriptive information about this implementation and the
57 * corresponding version number, in the format
58 * <code><description>/<version></code>.
59 */
60 public String getInfo() {
61 return (info);
62 }
63
64 public MultiPointSender getTransport() {
65 return transport;
66 }
67
68 public void setTransport(MultiPointSender transport) {
69 this.transport = transport;
70 }
71
72 // ------------------------------------------------------------- public
73
74 /**
75 * Send data to one member
76 * @see org.apache.catalina.tribes.ClusterSender#sendMessage(org.apache.catalina.tribes.ClusterMessage, org.apache.catalina.tribes.Member)
77 */
78 public void sendMessage(ChannelMessage message, Member[] destination) throws ChannelException {
79 MultiPointSender sender = getTransport();
80 sender.sendMessage(destination,message);
81 }
82
83
84 /**
85 * start the sender and register transmitter mbean
86 *
87 * @see org.apache.catalina.tribes.ClusterSender#start()
88 */
89 public void start() throws java.io.IOException {
90 getTransport().connect();
91 }
92
93 /*
94 * stop the sender and deregister mbeans (transmitter, senders)
95 *
96 * @see org.apache.catalina.tribes.ClusterSender#stop()
97 */
98 public synchronized void stop() {
99 getTransport().disconnect();
100 }
101
102 /**
103 * Call transmitter to check for sender socket status
104 *
105 * @see SimpleTcpCluster#backgroundProcess()
106 */
107
108 public void heartbeat() {
109 if (getTransport()!=null) getTransport().keepalive();
110 }
111
112 /**
113 * add new cluster member and create sender ( s. replicationMode) transfer
114 * current properties to sender
115 *
116 * @see org.apache.catalina.tribes.ClusterSender#add(org.apache.catalina.tribes.Member)
117 */
118 public synchronized void add(Member member) {
119 getTransport().add(member);
120 }
121
122 /**
123 * remove sender from transmitter. ( deregister mbean and disconnect sender )
124 *
125 * @see org.apache.catalina.tribes.ClusterSender#remove(org.apache.catalina.tribes.Member)
126 */
127 public synchronized void remove(Member member) {
128 getTransport().remove(member);
129 }
130
131 // ------------------------------------------------------------- protected
132
133
134
135 }