Search in sources :

Example 1 with Member

use of org.apache.catalina.tribes.Member in project tomcat by apache.

the class MultipointBioSender method close.

private synchronized void close() throws ChannelException {
    ChannelException x = null;
    Object[] members = bioSenders.keySet().toArray();
    for (int i = 0; i < members.length; i++) {
        Member mbr = (Member) members[i];
        try {
            BioSender sender = bioSenders.get(mbr);
            sender.disconnect();
        } catch (Exception e) {
            if (x == null)
                x = new ChannelException(e);
            x.addFaultyMember(mbr, e);
        }
        bioSenders.remove(mbr);
    }
    if (x != null)
        throw x;
}
Also used : Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException) IOException(java.io.IOException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 2 with Member

use of org.apache.catalina.tribes.Member in project tomcat70 by apache.

the class DeltaManager method getAllClusterSessions.

/**
 * get from first session master the backup from all clustered sessions
 * @see #findSessionMasterMember()
 */
public synchronized void getAllClusterSessions() {
    if (cluster != null && cluster.getMembers().length > 0) {
        long beforeSendTime = System.currentTimeMillis();
        Member mbr = findSessionMasterMember();
        if (mbr == null) {
            // No domain member found
            return;
        }
        SessionMessage msg = new SessionMessageImpl(this.getName(), SessionMessage.EVT_GET_ALL_SESSIONS, null, "GET-ALL", "GET-ALL-" + getName());
        msg.setTimestamp(beforeSendTime);
        // set reference time
        stateTransferCreateSendTime = beforeSendTime;
        // request session state
        counterSend_EVT_GET_ALL_SESSIONS++;
        stateTransfered = false;
        // FIXME This send call block the deploy thread, when sender waitForAck is enabled
        try {
            synchronized (receivedMessageQueue) {
                receiverQueue = true;
            }
            cluster.send(msg, mbr);
            if (log.isInfoEnabled())
                log.info(sm.getString("deltaManager.waitForSessionState", getName(), mbr, Integer.valueOf(getStateTransferTimeout())));
            // FIXME At sender ack mode this method check only the state transfer and resend is a problem!
            waitForSendAllSessions(beforeSendTime);
        } finally {
            synchronized (receivedMessageQueue) {
                for (Iterator<SessionMessage> iter = receivedMessageQueue.iterator(); iter.hasNext(); ) {
                    SessionMessage smsg = iter.next();
                    if (!stateTimestampDrop) {
                        messageReceived(smsg, smsg.getAddress() != null ? (Member) smsg.getAddress() : null);
                    } else {
                        if (smsg.getEventType() != SessionMessage.EVT_GET_ALL_SESSIONS && smsg.getTimestamp() >= stateTransferCreateSendTime) {
                            // FIXME handle EVT_GET_ALL_SESSIONS later
                            messageReceived(smsg, smsg.getAddress() != null ? (Member) smsg.getAddress() : null);
                        } else {
                            if (log.isWarnEnabled()) {
                                log.warn(sm.getString("deltaManager.dropMessage", getName(), smsg.getEventTypeString(), new Date(stateTransferCreateSendTime), new Date(smsg.getTimestamp())));
                            }
                        }
                    }
                }
                receivedMessageQueue.clear();
                receiverQueue = false;
            }
        }
    } else {
        if (log.isInfoEnabled())
            log.info(sm.getString("deltaManager.noMembers", getName()));
    }
}
Also used : Member(org.apache.catalina.tribes.Member) Date(java.util.Date)

Example 3 with Member

use of org.apache.catalina.tribes.Member in project tomcat70 by apache.

the class FarmWarDeployer method install.

/**
 * Install a new web application, whose web application archive is at the
 * specified URL, into this container and all the other members of the
 * cluster with the specified context name.
 * <p>
 * If this application is successfully installed locally, a ContainerEvent
 * of type <code>INSTALL_EVENT</code> will be sent to all registered
 * listeners, with the newly created <code>Context</code> as an argument.
 *
 * @param contextName
 *            The context name to which this application should be installed
 *            (must be unique)
 * @param webapp
 *            A WAR file or unpacked directory structure containing the web
 *            application to be installed
 *
 * @exception IllegalArgumentException
 *                if the specified context name is malformed
 * @exception IllegalStateException
 *                if the specified context name is already deployed
 * @exception IOException
 *                if an input/output error was encountered during
 *                installation
 */
@Override
public void install(String contextName, File webapp) throws IOException {
    Member[] members = getCluster().getMembers();
    if (members.length == 0)
        return;
    Member localMember = getCluster().getLocalMember();
    FileMessageFactory factory = FileMessageFactory.getInstance(webapp, false);
    FileMessage msg = new FileMessage(localMember, webapp.getName(), contextName);
    if (log.isDebugEnabled())
        log.debug(sm.getString("farmWarDeployer.sendStart", contextName, webapp));
    msg = factory.readMessage(msg);
    while (msg != null) {
        for (int i = 0; i < members.length; i++) {
            if (log.isDebugEnabled())
                log.debug(sm.getString("farmWarDeployer.sendFragment", contextName, webapp, members[i]));
            getCluster().send(msg, members[i]);
        }
        msg = factory.readMessage(msg);
    }
    if (log.isDebugEnabled())
        log.debug(sm.getString("farmWarDeployer.sendEnd", contextName, webapp));
}
Also used : Member(org.apache.catalina.tribes.Member)

Example 4 with Member

use of org.apache.catalina.tribes.Member in project tomcat70 by apache.

the class ChannelCreator method createChannel.

public static Channel createChannel(String[] args) throws Exception {
    String bind = "auto";
    int port = 4001;
    String mbind = null;
    boolean gzip = false;
    int tcpseltimeout = 5000;
    int tcpthreadcount = 4;
    int acktimeout = 15000;
    String mcastaddr = "228.0.0.5";
    int mcastport = 45565;
    long mcastfreq = 500;
    long mcastdrop = 2000;
    boolean order = false;
    int ordersize = Integer.MAX_VALUE;
    boolean frag = false;
    int fragsize = 1024;
    int autoBind = 10;
    ArrayList<Member> staticMembers = new ArrayList<Member>();
    Properties transportProperties = new Properties();
    String transport = "org.apache.catalina.tribes.transport.nio.PooledParallelSender";
    String receiver = "org.apache.catalina.tribes.transport.nio.NioReceiver";
    boolean async = false;
    // 50MB
    int asyncsize = 1024 * 1024 * 50;
    boolean throughput = false;
    boolean failuredetect = false;
    for (int i = 0; i < args.length; i++) {
        if ("-bind".equals(args[i])) {
            bind = args[++i];
        } else if ("-port".equals(args[i])) {
            port = Integer.parseInt(args[++i]);
        } else if ("-autobind".equals(args[i])) {
            autoBind = Integer.parseInt(args[++i]);
        } else if ("-tcpselto".equals(args[i])) {
            tcpseltimeout = Integer.parseInt(args[++i]);
        } else if ("-tcpthreads".equals(args[i])) {
            tcpthreadcount = Integer.parseInt(args[++i]);
        } else if ("-gzip".equals(args[i])) {
            gzip = true;
        } else if ("-async".equals(args[i])) {
            async = true;
        } else if ("-failuredetect".equals(args[i])) {
            failuredetect = true;
        } else if ("-asyncsize".equals(args[i])) {
            asyncsize = Integer.parseInt(args[++i]);
            System.out.println("Setting MessageDispatchInterceptor.maxQueueSize=" + asyncsize);
        } else if ("-static".equals(args[i])) {
            String d = args[++i];
            String h = d.substring(0, d.indexOf(':'));
            String p = d.substring(h.length() + 1);
            MemberImpl m = new MemberImpl(h, Integer.parseInt(p), 2000);
            staticMembers.add(m);
        } else if ("-throughput".equals(args[i])) {
            throughput = true;
        } else if ("-order".equals(args[i])) {
            order = true;
        } else if ("-ordersize".equals(args[i])) {
            ordersize = Integer.parseInt(args[++i]);
            System.out.println("Setting OrderInterceptor.maxQueue=" + ordersize);
        } else if ("-frag".equals(args[i])) {
            frag = true;
        } else if ("-fragsize".equals(args[i])) {
            fragsize = Integer.parseInt(args[++i]);
            System.out.println("Setting FragmentationInterceptor.maxSize=" + fragsize);
        } else if ("-ackto".equals(args[i])) {
            acktimeout = Integer.parseInt(args[++i]);
        } else if ("-transport".equals(args[i])) {
            transport = args[++i];
        } else if (args[i] != null && args[i].startsWith("transport.")) {
            String key = args[i];
            String val = args[++i];
            transportProperties.setProperty(key, val);
        } else if ("-receiver".equals(args[i])) {
            receiver = args[++i];
        } else if ("-maddr".equals(args[i])) {
            mcastaddr = args[++i];
        } else if ("-mport".equals(args[i])) {
            mcastport = Integer.parseInt(args[++i]);
        } else if ("-mfreq".equals(args[i])) {
            mcastfreq = Long.parseLong(args[++i]);
        } else if ("-mdrop".equals(args[i])) {
            mcastdrop = Long.parseLong(args[++i]);
        } else if ("-mbind".equals(args[i])) {
            mbind = args[++i];
        }
    }
    System.out.println("Creating receiver class=" + receiver);
    Class<?> cl = Class.forName(receiver, true, ChannelCreator.class.getClassLoader());
    ReceiverBase rx = (ReceiverBase) cl.newInstance();
    rx.setAddress(bind);
    rx.setPort(port);
    rx.setSelectorTimeout(tcpseltimeout);
    rx.setMaxThreads(tcpthreadcount);
    rx.setMinThreads(tcpthreadcount);
    rx.getBind();
    rx.setRxBufSize(43800);
    rx.setTxBufSize(25188);
    rx.setAutoBind(autoBind);
    ReplicationTransmitter ps = new ReplicationTransmitter();
    System.out.println("Creating transport class=" + transport);
    MultiPointSender sender = (MultiPointSender) Class.forName(transport, true, ChannelCreator.class.getClassLoader()).newInstance();
    sender.setTimeout(acktimeout);
    sender.setMaxRetryAttempts(2);
    sender.setRxBufSize(43800);
    sender.setTxBufSize(25188);
    Iterator<Object> i = transportProperties.keySet().iterator();
    while (i.hasNext()) {
        String key = (String) i.next();
        IntrospectionUtils.setProperty(sender, key, transportProperties.getProperty(key));
    }
    ps.setTransport(sender);
    McastService service = new McastService();
    service.setAddress(mcastaddr);
    if (mbind != null)
        service.setMcastBindAddress(mbind);
    service.setFrequency(mcastfreq);
    service.setMcastDropTime(mcastdrop);
    service.setPort(mcastport);
    ManagedChannel channel = new GroupChannel();
    channel.setChannelReceiver(rx);
    channel.setChannelSender(ps);
    channel.setMembershipService(service);
    if (throughput)
        channel.addInterceptor(new ThroughputInterceptor());
    if (gzip)
        channel.addInterceptor(new GzipInterceptor());
    if (frag) {
        FragmentationInterceptor fi = new FragmentationInterceptor();
        fi.setMaxSize(fragsize);
        channel.addInterceptor(fi);
    }
    if (order) {
        OrderInterceptor oi = new OrderInterceptor();
        oi.setMaxQueue(ordersize);
        channel.addInterceptor(oi);
    }
    if (async) {
        MessageDispatchInterceptor mi = new MessageDispatch15Interceptor();
        mi.setMaxQueueSize(asyncsize);
        channel.addInterceptor(mi);
        System.out.println("Added MessageDispatchInterceptor");
    }
    if (failuredetect) {
        TcpFailureDetector tcpfi = new TcpFailureDetector();
        channel.addInterceptor(tcpfi);
    }
    if (staticMembers.size() > 0) {
        StaticMembershipInterceptor smi = new StaticMembershipInterceptor();
        for (int x = 0; x < staticMembers.size(); x++) {
            smi.addStaticMember(staticMembers.get(x));
        }
        channel.addInterceptor(smi);
    }
    byte[] domain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    ((McastService) channel.getMembershipService()).setDomain(domain);
    DomainFilterInterceptor filter = new DomainFilterInterceptor();
    filter.setDomain(domain);
    channel.addInterceptor(filter);
    return channel;
}
Also used : ReceiverBase(org.apache.catalina.tribes.transport.ReceiverBase) MultiPointSender(org.apache.catalina.tribes.transport.MultiPointSender) StaticMembershipInterceptor(org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor) ArrayList(java.util.ArrayList) FragmentationInterceptor(org.apache.catalina.tribes.group.interceptors.FragmentationInterceptor) TcpFailureDetector(org.apache.catalina.tribes.group.interceptors.TcpFailureDetector) Properties(java.util.Properties) GzipInterceptor(org.apache.catalina.tribes.group.interceptors.GzipInterceptor) OrderInterceptor(org.apache.catalina.tribes.group.interceptors.OrderInterceptor) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Member(org.apache.catalina.tribes.Member) DomainFilterInterceptor(org.apache.catalina.tribes.group.interceptors.DomainFilterInterceptor) MessageDispatchInterceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor) MemberImpl(org.apache.catalina.tribes.membership.MemberImpl) GroupChannel(org.apache.catalina.tribes.group.GroupChannel) ReplicationTransmitter(org.apache.catalina.tribes.transport.ReplicationTransmitter) MessageDispatch15Interceptor(org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor) ThroughputInterceptor(org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor) McastService(org.apache.catalina.tribes.membership.McastService)

Example 5 with Member

use of org.apache.catalina.tribes.Member in project tomcat70 by apache.

the class TestGroupChannelSenderConnections method sendMessages.

public void sendMessages(long delay, long sleep) throws Exception {
    resetMessageCounters();
    Member local = channels[0].getLocalMember(true);
    Member dest = channels[1].getLocalMember(true);
    int n = 3;
    log.info("Sending " + n + " messages from [" + local.getName() + "] to [" + dest.getName() + "] with delay of " + delay + " ms between them.");
    for (int i = 0; i < n; i++) {
        channels[0].send(new Member[] { dest }, new TestMsg(), 0);
        boolean last = (i == n - 1);
        if (!last && delay > 0) {
            Thread.sleep(delay);
        }
    }
    log.info("Messages sent. Waiting no more than " + (sleep / 1000) + " seconds for them to be received");
    long startTime = System.currentTimeMillis();
    int countReceived;
    while ((countReceived = getReceivedMessageCount()) != n) {
        long time = System.currentTimeMillis();
        if ((time - startTime) > sleep) {
            Assert.fail("Only " + countReceived + " out of " + n + " messages have been received in " + (sleep / 1000) + " seconds");
            break;
        }
        Thread.sleep(100);
    }
}
Also used : Member(org.apache.catalina.tribes.Member)

Aggregations

Member (org.apache.catalina.tribes.Member)93 ChannelException (org.apache.catalina.tribes.ChannelException)28 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)17 Test (org.junit.Test)17 IOException (java.io.IOException)16 MemberImpl (org.apache.catalina.tribes.membership.MemberImpl)15 ReceiverBase (org.apache.catalina.tribes.transport.ReceiverBase)11 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 UniqueId (org.apache.catalina.tribes.UniqueId)9 Serializable (java.io.Serializable)6 BigDecimal (java.math.BigDecimal)6 DecimalFormat (java.text.DecimalFormat)6 Response (org.apache.catalina.tribes.group.Response)6 ChannelData (org.apache.catalina.tribes.io.ChannelData)6 XByteBuffer (org.apache.catalina.tribes.io.XByteBuffer)6 SelectionKey (java.nio.channels.SelectionKey)4 Selector (java.nio.channels.Selector)4 Membership (org.apache.catalina.tribes.membership.Membership)4 StaticMember (org.apache.catalina.tribes.membership.StaticMember)4