Search in sources :

Example 1 with RpcChannel

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

Aggregations

ChannelException (org.apache.catalina.tribes.ChannelException)1 RpcChannel (org.apache.catalina.tribes.group.RpcChannel)1