Search in sources :

Example 6 with ChannelException

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

the class AbstractReplicatedMap method transferState.

public void transferState() {
    try {
        Member[] members = getMapMembers();
        Member backup = members.length > 0 ? (Member) members[0] : null;
        if (backup != null) {
            MapMessage msg = new MapMessage(mapContextName, getStateMessageType(), false, null, null, null, null, null);
            Response[] resp = rpcChannel.send(new Member[] { backup }, msg, RpcChannel.FIRST_REPLY, channelSendOptions, rpcTimeout);
            if (resp.length > 0) {
                synchronized (stateMutex) {
                    msg = (MapMessage) resp[0].getMessage();
                    msg.deserialize(getExternalLoaders());
                    ArrayList<?> list = (ArrayList<?>) msg.getValue();
                    for (int i = 0; i < list.size(); i++) {
                        messageReceived((Serializable) list.get(i), resp[0].getSource());
                    }
                //for
                }
                stateTransferred = true;
            } else {
                log.warn(sm.getString("abstractReplicatedMap.transferState.noReplies"));
            }
        }
    } catch (ChannelException x) {
        log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
    } catch (IOException x) {
        log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
    } catch (ClassNotFoundException x) {
        log.error(sm.getString("abstractReplicatedMap.unable.transferState"), x);
    }
}
Also used : Response(org.apache.catalina.tribes.group.Response) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 7 with ChannelException

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

the class AbstractReplicatedMap method mapMemberAdded.

public void mapMemberAdded(Member member) {
    if (member.equals(getChannel().getLocalMember(false)))
        return;
    boolean memberAdded = false;
    //select a backup node if we don't have one
    Member mapMember = getChannel().getMember(member);
    if (mapMember == null) {
        log.warn(sm.getString("abstractReplicatedMap.mapMemberAdded.nullMember", member));
        return;
    }
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(mapMember)) {
            if (log.isInfoEnabled())
                log.info(sm.getString("abstractReplicatedMap.mapMemberAdded.added", mapMember));
            mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if (memberAdded) {
        synchronized (stateMutex) {
            Iterator<Map.Entry<K, MapEntry<K, V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K, MapEntry<K, V>> e = i.next();
                MapEntry<K, V> entry = innerMap.get(e.getKey());
                if (entry == null)
                    continue;
                if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
                    try {
                        Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                        entry.setBackupNodes(backup);
                        entry.setPrimary(channel.getLocalMember(false));
                    } catch (ChannelException x) {
                        log.error(sm.getString("abstractReplicatedMap.unableSelect.backup"), x);
                    }
                //catch
                }
            //end if
            }
        //while
        }
    //synchronized
    }
//end if
}
Also used : FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 8 with ChannelException

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

the class AbstractReplicatedMap method init.

/**
     * Initializes the map by creating the RPC channel, registering itself as a channel listener
     * This method is also responsible for initiating the state transfer
     * @param owner Object
     * @param channel Channel
     * @param mapContextName String
     * @param timeout long
     * @param channelSendOptions int
     * @param cls ClassLoader[]
     * @param terminate - Flag for whether to terminate this map that failed to start.
     */
protected void init(MapOwner owner, Channel channel, String mapContextName, long timeout, int channelSendOptions, ClassLoader[] cls, boolean terminate) {
    long start = System.currentTimeMillis();
    if (log.isInfoEnabled())
        log.info(sm.getString("abstractReplicatedMap.init.start", mapContextName));
    this.mapOwner = owner;
    this.externalLoaders = cls;
    this.channelSendOptions = channelSendOptions;
    this.channel = channel;
    this.rpcTimeout = timeout;
    this.mapname = mapContextName;
    //unique context is more efficient if it is stored as bytes
    this.mapContextName = mapContextName.getBytes(StandardCharsets.ISO_8859_1);
    if (log.isTraceEnabled())
        log.trace("Created Lazy Map with name:" + mapContextName + ", bytes:" + Arrays.toString(this.mapContextName));
    //create an rpc channel and add the map as a listener
    this.rpcChannel = new RpcChannel(this.mapContextName, channel, this);
    //add this map as a message listener
    this.channel.addChannelListener(this);
    //listen for membership notifications
    this.channel.addMembershipListener(this);
    try {
        //broadcast our map, this just notifies other members of our existence
        broadcast(MapMessage.MSG_INIT, true);
        //transfer state from another map
        transferState();
        //state is transferred, we are ready for messaging
        broadcast(MapMessage.MSG_START, true);
    } catch (ChannelException x) {
        log.warn(sm.getString("abstractReplicatedMap.unableSend.startMessage"));
        if (terminate) {
            breakdown();
            throw new RuntimeException(sm.getString("abstractReplicatedMap.unableStart"), x);
        }
    }
    this.state = State.INITIALIZED;
    long complete = System.currentTimeMillis() - start;
    if (log.isInfoEnabled())
        log.info(sm.getString("abstractReplicatedMap.init.completed", mapContextName, Long.toString(complete)));
}
Also used : RpcChannel(org.apache.catalina.tribes.group.RpcChannel) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 9 with ChannelException

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

the class MultipointBioSender method sendMessage.

@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
    BioSender[] senders = setupForSend(destination);
    ChannelException cx = null;
    for (int i = 0; i < senders.length; i++) {
        try {
            senders[i].sendMessage(data, (msg.getOptions() & Channel.SEND_OPTIONS_USE_ACK) == Channel.SEND_OPTIONS_USE_ACK);
        } catch (Exception x) {
            if (cx == null)
                cx = new ChannelException(x);
            cx.addFaultyMember(destination[i], x);
        }
    }
    if (cx != null)
        throw cx;
}
Also used : ChannelException(org.apache.catalina.tribes.ChannelException) IOException(java.io.IOException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 10 with ChannelException

use of org.apache.catalina.tribes.ChannelException 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)

Aggregations

ChannelException (org.apache.catalina.tribes.ChannelException)27 IOException (java.io.IOException)10 Member (org.apache.catalina.tribes.Member)8 UnknownHostException (java.net.UnknownHostException)4 UniqueId (org.apache.catalina.tribes.UniqueId)4 Test (org.junit.Test)4 ByteMessage (org.apache.catalina.tribes.ByteMessage)3 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)3 ChannelInterceptor (org.apache.catalina.tribes.ChannelInterceptor)3 Serializable (java.io.Serializable)2 Response (org.apache.catalina.tribes.group.Response)2 ChannelData (org.apache.catalina.tribes.io.ChannelData)2 XByteBuffer (org.apache.catalina.tribes.io.XByteBuffer)2 DatagramPacket (java.net.DatagramPacket)1 SelectionKey (java.nio.channels.SelectionKey)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1