org.apache.catalina.tribes.ChannelMessage

Here are the examples of the java api org.apache.catalina.tribes.ChannelMessage taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

92 Examples 7

19 Source : Arrays.java
with Apache License 2.0
from wangyingjie

public static UniqueId getUniqudId(ChannelMessage msg) {
    return new UniqueId(msg.getUniqueId());
}

19 Source : ReplicationTransmitter.java
with Apache License 2.0
from wangyingjie

// ------------------------------------------------------------- public
/**
 * Send data to one member
 * @see org.apache.catalina.tribes.ChannelSender#sendMessage(org.apache.catalina.tribes.ChannelMessage, org.apache.catalina.tribes.Member[])
 */
@Override
public void sendMessage(ChannelMessage message, Member[] destination) throws ChannelException {
    MultiPointSender sender = getTransport();
    sender.sendMessage(destination, message);
}

19 Source : McastService.java
with Apache License 2.0
from wangyingjie

@Override
public boolean accept(ChannelMessage msg) {
    return true;
}

19 Source : McastService.java
with Apache License 2.0
from wangyingjie

@Override
public void broadcast(ChannelMessage message) throws ChannelException {
    if (impl == null || (impl.startLevel & Channel.MBR_TX_SEQ) != Channel.MBR_TX_SEQ)
        throw new ChannelException("Multicast send is not started or enabled.");
    byte[] data = XByteBuffer.createDataPackage((ChannelData) message);
    if (data.length > McastServiceImpl.MAX_PACKET_SIZE) {
        throw new ChannelException("Packet length[" + data.length + "] exceeds max packet size of " + McastServiceImpl.MAX_PACKET_SIZE + " bytes.");
    }
    DatagramPacket packet = new DatagramPacket(data, 0, data.length);
    try {
        impl.send(false, packet);
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}

19 Source : ObjectReader.java
with Apache License 2.0
from wangyingjie

/**
 * Send buffer to cluster listener (callback).
 * Is message complete receiver send message to callback?
 *
 * @see org.apache.catalina.tribes.transport.ReceiverBase#messageDataReceived(ChannelMessage)
 * @see XByteBuffer#doesPackageExist()
 * @see XByteBuffer#extractPackage(boolean)
 *
 * @return number of received packages/messages
 * @throws java.io.IOException
 */
public ChannelMessage[] execute() throws java.io.IOException {
    int pkgCnt = buffer.countPackages();
    ChannelMessage[] result = new ChannelMessage[pkgCnt];
    for (int i = 0; i < pkgCnt; i++) {
        ChannelMessage data = buffer.extractPackage(true);
        result[i] = data;
    }
    return result;
}

19 Source : ThroughputInterceptor.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    if (rxStart == 0)
        rxStart = System.currentTimeMillis();
    long bytes = XByteBuffer.getDataPackageLength(((ChannelData) msg).getDataPackageLength());
    mbRx += bytes / (1024d * 1024d);
    msgRxCnt.addAndGet(1);
    if (msgRxCnt.get() % interval == 0)
        report(timeTx);
    super.messageReceived(msg);
}

19 Source : FragmentationInterceptor.java
with Apache License 2.0
from wangyingjie

public void defrag(ChannelMessage msg) {
    FragKey key = new FragKey(msg.getUniqueId());
    FragCollection coll = getFragCollection(key, msg);
    coll.addMessage((ChannelMessage) msg.deepclone());
    if (coll.complete()) {
        removeFragCollection(key);
        ChannelMessage complete = coll.replacedemble();
        super.messageReceived(complete);
    }
}

19 Source : FragmentationInterceptor.java
with Apache License 2.0
from wangyingjie

public FragCollection getFragCollection(FragKey key, ChannelMessage msg) {
    FragCollection coll = fragpieces.get(key);
    if (coll == null) {
        synchronized (fragpieces) {
            coll = fragpieces.get(key);
            if (coll == null) {
                coll = new FragCollection(msg);
                fragpieces.put(key, coll);
            }
        }
    }
    return coll;
}

19 Source : ChannelInterceptorBase.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    if (getPrevious() != null)
        getPrevious().messageReceived(msg);
}

19 Source : ChannelInterceptorBase.java
with Apache License 2.0
from wangyingjie

public boolean accept(ChannelMessage msg) {
    return true;
}

19 Source : ChannelInterceptorBase.java
with Apache License 2.0
from wangyingjie

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (getNext() != null)
        getNext().sendMessage(destination, msg, payload);
}

19 Source : ChannelCoordinator.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    if (Logs.MESSAGES.isTraceEnabled()) {
        Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " from " + msg.getAddress().getName());
    }
    super.messageReceived(msg);
}

19 Source : ReplicationTransmitter.java
with Apache License 2.0
from how2j

// ------------------------------------------------------------- public
/**
 * Send data to one member
 *
 * @see org.apache.catalina.tribes.ChannelSender#sendMessage(org.apache.catalina.tribes.ChannelMessage,
 *      org.apache.catalina.tribes.Member[])
 */
@Override
public void sendMessage(ChannelMessage message, Member[] destination) throws ChannelException {
    MultiPointSender sender = getTransport();
    sender.sendMessage(destination, message);
}

19 Source : ObjectReader.java
with Apache License 2.0
from how2j

/**
 * Send buffer to cluster listener (callback). Is message complete receiver
 * send message to callback?
 *
 * @see org.apache.catalina.tribes.transport.ReceiverBase#messageDataReceived(ChannelMessage)
 * @see XByteBuffer#doesPackageExist()
 * @see XByteBuffer#extractPackage(boolean)
 *
 * @return number of received packages/messages
 * @throws java.io.IOException
 */
public ChannelMessage[] execute() throws java.io.IOException {
    int pkgCnt = buffer.countPackages();
    ChannelMessage[] result = new ChannelMessage[pkgCnt];
    for (int i = 0; i < pkgCnt; i++) {
        ChannelMessage data = buffer.extractPackage(true);
        result[i] = data;
    }
    return result;
}

19 Source : BioReplicationTask.java
with GNU General Public License v3.0
from guang19

protected void execute(ObjectReader reader) throws Exception {
    int pkgcnt = reader.count();
    if (pkgcnt > 0) {
        ChannelMessage[] msgs = reader.execute();
        for (int i = 0; i < msgs.length; i++) {
            /**
             * Use send ack here if you want to ack the request to the remote
             * server before completing the request
             * This is considered an asynchronous request
             */
            if (ChannelData.sendAckAsync(msgs[i].getOptions()))
                sendAck(Constants.ACK_COMMAND);
            try {
                // process the message
                getCallback().messageDataReceived(msgs[i]);
                /**
                 * Use send ack here if you want the request to complete on this
                 * server before sending the ack to the remote server
                 * This is considered a synchronized request
                 */
                if (ChannelData.sendAckSync(msgs[i].getOptions()))
                    sendAck(Constants.ACK_COMMAND);
            } catch (Exception x) {
                if (ChannelData.sendAckSync(msgs[i].getOptions()))
                    sendAck(Constants.FAIL_ACK_COMMAND);
                log.error(sm.getString("bioReplicationTask.messageDataReceived.error"), x);
            }
            if (getUseBufferPool()) {
                BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
                msgs[i].setMessage(null);
            }
        }
    }
}

19 Source : MembershipServiceBase.java
with GNU General Public License v3.0
from guang19

@Override
public void broadcast(ChannelMessage message) throws ChannelException {
// no-op
}

19 Source : McastService.java
with GNU General Public License v3.0
from guang19

@Override
public void broadcast(ChannelMessage message) throws ChannelException {
    if (impl == null || (impl.startLevel & Channel.MBR_TX_SEQ) != Channel.MBR_TX_SEQ)
        throw new ChannelException(sm.getString("mcastService.noStart"));
    byte[] data = XByteBuffer.createDataPackage((ChannelData) message);
    if (data.length > McastServiceImpl.MAX_PACKET_SIZE) {
        throw new ChannelException(sm.getString("mcastService.exceed.maxPacketSize", Integer.toString(data.length), Integer.toString(McastServiceImpl.MAX_PACKET_SIZE)));
    }
    DatagramPacket packet = new DatagramPacket(data, 0, data.length);
    try {
        impl.send(false, packet);
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}

19 Source : ObjectReader.java
with GNU General Public License v3.0
from guang19

/**
 * Send buffer to cluster listener (callback).
 * Is message complete receiver send message to callback?
 *
 * @see org.apache.catalina.tribes.transport.ReceiverBase#messageDataReceived(ChannelMessage)
 * @see XByteBuffer#doesPackageExist()
 * @see XByteBuffer#extractPackage(boolean)
 *
 * @return number of received packages/messages
 */
public ChannelMessage[] execute() {
    int pkgCnt = buffer.countPackages();
    ChannelMessage[] result = new ChannelMessage[pkgCnt];
    for (int i = 0; i < pkgCnt; i++) {
        ChannelMessage data = buffer.extractPackage(true);
        result[i] = data;
    }
    return result;
}

18 Source : PooledParallelSender.java
with Apache License 2.0
from wangyingjie

@Override
public void sendMessage(Member[] destination, ChannelMessage message) throws ChannelException {
    if (!connected)
        throw new ChannelException("Sender not connected.");
    ParallelNioSender sender = (ParallelNioSender) getSender();
    if (sender == null) {
        ChannelException cx = new ChannelException("Unable to retrieve a data sender, time out(" + getMaxWait() + " ms) error.");
        for (int i = 0; i < destination.length; i++) cx.addFaultyMember(destination[i], new NullPointerException("Unable to retrieve a sender from the sender pool"));
        throw cx;
    } else {
        try {
            sender.sendMessage(destination, message);
            sender.keepalive();
        } catch (ChannelException x) {
            sender.disconnect();
            throw x;
        } finally {
            returnSender(sender);
            if (!connected)
                disconnect();
        }
    }
}

18 Source : ParallelNioSender.java
with Apache License 2.0
from wangyingjie

@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    long start = System.currentTimeMillis();
    this.setUdpBased((msg.getOptions() & Channel.SEND_OPTIONS_UDP) == Channel.SEND_OPTIONS_UDP);
    byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
    NioSender[] senders = setupForSend(destination);
    connect(senders);
    setData(senders, data);
    int remaining = senders.length;
    ChannelException cx = null;
    try {
        // loop until complete, an error happens, or we timeout
        long delta = System.currentTimeMillis() - start;
        boolean waitForAck = (Channel.SEND_OPTIONS_USE_ACK & msg.getOptions()) == Channel.SEND_OPTIONS_USE_ACK;
        while ((remaining > 0) && (delta < getTimeout())) {
            try {
                remaining -= doLoop(selectTimeout, getMaxRetryAttempts(), waitForAck, msg);
            } catch (Exception x) {
                if (log.isTraceEnabled())
                    log.trace("Error sending message", x);
                int faulty = (cx == null) ? 0 : cx.getFaultyMembers().length;
                if (cx == null) {
                    if (x instanceof ChannelException)
                        cx = (ChannelException) x;
                    else
                        cx = new ChannelException("Parallel NIO send failed.", x);
                } else {
                    if (x instanceof ChannelException)
                        cx.addFaultyMember(((ChannelException) x).getFaultyMembers());
                }
                // count down the remaining on an error
                if (faulty < cx.getFaultyMembers().length)
                    remaining -= (cx.getFaultyMembers().length - faulty);
            }
            // bail out if all remaining senders are failing
            if (cx != null && cx.getFaultyMembers().length == remaining)
                throw cx;
            delta = System.currentTimeMillis() - start;
        }
        if (remaining > 0) {
            // timeout has occurred
            ChannelException cxtimeout = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            if (cx == null)
                cx = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            for (int i = 0; i < senders.length; i++) {
                if (!senders[i].isComplete())
                    cx.addFaultyMember(senders[i].getDestination(), cxtimeout);
            }
            throw cx;
        } else if (cx != null) {
            // there was an error
            throw cx;
        }
    } catch (Exception x) {
        try {
            this.disconnect();
        } catch (Exception e) {
        /*Ignore*/
        }
        if (x instanceof ChannelException)
            throw (ChannelException) x;
        else
            throw new ChannelException(x);
    }
}

18 Source : LinkObject.java
with Apache License 2.0
from wangyingjie

/**
 * The clreplaced <b>LinkObject</b> implements an element
 * for a linked list, consisting of a general
 * data object and a pointer to the next element.
 *
 * @author Rainer Jung
 * @author Peter Rossbach
 * @author Filip Hanik
 */
public clreplaced LinkObject {

    private ChannelMessage msg;

    private LinkObject next;

    private byte[] key;

    private Member[] destination;

    private InterceptorPayload payload;

    /**
     * Construct a new element from the data object.
     * Sets the pointer to null.
     *
     * @param msg the message
     * @param destination TBA
     * @param payload The data object.
     */
    public LinkObject(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
        this.msg = msg;
        this.next = null;
        this.key = msg.getUniqueId();
        this.payload = payload;
        this.destination = destination;
    }

    /**
     * Set the next element.
     * @param next The next element.
     */
    public void append(LinkObject next) {
        this.next = next;
    }

    /**
     * Get the next element.
     * @return The next element.
     */
    public LinkObject next() {
        return next;
    }

    public void setNext(LinkObject next) {
        this.next = next;
    }

    /**
     * Get the data object from the element.
     * @return The data object from the element.
     */
    public ChannelMessage data() {
        return msg;
    }

    /**
     * Get the unique message id
     * @return the unique message id
     */
    public byte[] getKey() {
        return key;
    }

    public ErrorHandler getHandler() {
        return payload != null ? payload.getErrorHandler() : null;
    }

    public InterceptorPayload getPayload() {
        return payload;
    }

    public Member[] getDestination() {
        return destination;
    }
}

18 Source : FastQueue.java
with Apache License 2.0
from wangyingjie

/**
 * Add new data to the queue.
 *
 * FIXME extract some method
 */
public boolean add(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
    boolean ok = true;
    if (!enabled) {
        if (log.isInfoEnabled())
            log.info("FastQueue.add: queue disabled, add aborted");
        return false;
    }
    lock.lockAdd();
    try {
        if (log.isTraceEnabled()) {
            log.trace("FastQueue.add: starting with size " + size);
        }
        if (checkLock) {
            if (inAdd)
                log.warn("FastQueue.add: Detected other add");
            inAdd = true;
            if (inMutex)
                log.warn("FastQueue.add: Detected other mutex in add");
            inMutex = true;
        }
        if ((maxQueueLength > 0) && (size >= maxQueueLength)) {
            ok = false;
            if (log.isTraceEnabled()) {
                log.trace("FastQueue.add: Could not add, since queue is full (" + size + ">=" + maxQueueLength + ")");
            }
        } else {
            LinkObject element = new LinkObject(msg, destination, payload);
            if (size == 0) {
                first = last = element;
                size = 1;
            } else {
                if (last == null) {
                    ok = false;
                    log.error("FastQueue.add: Could not add, since last is null although size is " + size + " (>0)");
                } else {
                    last.append(element);
                    last = element;
                    size++;
                }
            }
        }
        if (first == null) {
            log.error("FastQueue.add: first is null, size is " + size + " at end of add");
        }
        if (last == null) {
            log.error("FastQueue.add: last is null, size is " + size + " at end of add");
        }
        if (checkLock) {
            if (!inMutex)
                log.warn("FastQueue.add: Cancelled by other mutex in add");
            inMutex = false;
            if (!inAdd)
                log.warn("FastQueue.add: Cancelled by other add");
            inAdd = false;
        }
        if (log.isTraceEnabled())
            log.trace("FastQueue.add: add ending with size " + size);
    } finally {
        lock.unlockAdd(true);
    }
    return ok;
}

18 Source : MultipointBioSender.java
with Apache License 2.0
from wangyingjie

@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;
}

18 Source : McastService.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    if (msglistener != null && msglistener.accept(msg))
        msglistener.messageReceived(msg);
}

18 Source : ThroughputInterceptor.java
with Apache License 2.0
from wangyingjie

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (access.addAndGet(1) == 1)
        txStart = System.currentTimeMillis();
    long bytes = XByteBuffer.getDataPackageLength(((ChannelData) msg).getDataPackageLength());
    try {
        super.sendMessage(destination, msg, payload);
    } catch (ChannelException x) {
        msgTxErr.addAndGet(1);
        if (access.get() == 1)
            access.addAndGet(-1);
        throw x;
    }
    mbTx += (bytes * destination.length) / (1024d * 1024d);
    mbAppTx += bytes / (1024d * 1024d);
    if (access.addAndGet(-1) == 0) {
        long stop = System.currentTimeMillis();
        timeTx += (stop - txStart) / 1000d;
        if ((msgTxCnt.get() / interval) >= lastCnt) {
            lastCnt++;
            report(timeTx);
        }
    }
    msgTxCnt.addAndGet(1);
}

18 Source : TcpPingInterceptor.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    // catch incoming
    boolean process = true;
    if (okToProcess(msg.getOptions())) {
        // check to see if it is a ping message, if so, process = false
        process = ((msg.getMessage().getLength() != TCP_PING_DATA.length) || (!Arrays.equals(TCP_PING_DATA, msg.getMessage().getBytes())));
    }
    // end if
    // ignore the message, it doesnt have the flag set
    if (process)
        super.messageReceived(msg);
    else if (log.isDebugEnabled())
        log.debug("Received a TCP ping packet:" + msg);
}

18 Source : TcpFailureDetector.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    // catch incoming
    boolean process = true;
    if (okToProcess(msg.getOptions())) {
        // check to see if it is a testMessage, if so, process = false
        process = ((msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT, msg.getMessage().getBytes())));
    }
    // end if
    // ignore the message, it doesnt have the flag set
    if (process)
        super.messageReceived(msg);
    else if (log.isDebugEnabled())
        log.debug("Received a failure detector packet:" + msg);
}

18 Source : TcpFailureDetector.java
with Apache License 2.0
from wangyingjie

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    } catch (ChannelException cx) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for (int i = 0; i < mbrs.length; i++) {
            if (mbrs[i].getCause() != null && (!(mbrs[i].getCause() instanceof RemoteProcessException))) {
                // RemoteProcessException's are ok
                this.memberDisappeared(mbrs[i].getMember());
            }
        // end if
        }
        // for
        throw cx;
    }
}

18 Source : NonBlockingCoordinator.java
with Apache License 2.0
from wangyingjie

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    waitForRelease();
    super.sendMessage(destination, msg, payload);
}

18 Source : NonBlockingCoordinator.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    if (Arrays.contains(msg.getMessage().getBytesDirect(), 0, COORD_ALIVE, 0, COORD_ALIVE.length)) {
        // ignore message, its an alive message
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE, this, "Alive Message"));
    } else if (Arrays.contains(msg.getMessage().getBytesDirect(), 0, COORD_HEADER, 0, COORD_HEADER.length)) {
        try {
            CoordinationMessage cmsg = new CoordinationMessage(msg.getMessage());
            Member[] cmbr = cmsg.getMembers();
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE, this, "Coord Msg Arrived(" + Arrays.toNameString(cmbr) + ")"));
            processCoordMessage(cmsg, msg.getAddress());
        } catch (ChannelException x) {
            log.error("Error processing coordination message. Could be fatal.", x);
        }
    } else {
        super.messageReceived(msg);
    }
}

18 Source : MessageDispatch15Interceptor.java
with Apache License 2.0
from wangyingjie

@Override
public boolean addToQueue(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
    final LinkObject obj = new LinkObject(msg, destination, payload);
    Runnable r = new Runnable() {

        @Override
        public void run() {
            sendAsyncData(obj);
        }
    };
    executor.execute(r);
    return true;
}

18 Source : FragmentationInterceptor.java
with Apache License 2.0
from wangyingjie

@Override
public void messageReceived(ChannelMessage msg) {
    boolean isFrag = XByteBuffer.toBoolean(msg.getMessage().getBytesDirect(), msg.getMessage().getLength() - 1);
    msg.getMessage().trim(1);
    if (isFrag) {
        defrag(msg);
    } else {
        super.messageReceived(msg);
    }
}

18 Source : ChannelCoordinator.java
with Apache License 2.0
from wangyingjie

/**
 * Send a message to one or more members in the cluster
 * @param destination Member[] - the destinations, null or zero length means all
 * @param msg ClusterMessage - the message to send
 * @param payload TBA
 */
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (destination == null)
        destination = membershipService.getMembers();
    if ((msg.getOptions() & Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) {
        membershipService.broadcast(msg);
    } else {
        clusterSender.sendMessage(msg, destination);
    }
    if (Logs.MESSAGES.isTraceEnabled()) {
        Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " to " + Arrays.toNameString(destination));
    }
}

18 Source : 748.java
with MIT License
from masud-technope

@Override
public void messageReceived(ChannelMessage msg) {
    // catch incoming
    boolean process = true;
    if (okToProcess(msg.getOptions())) {
        // check to see if it is a testMessage, if so, process = false
        process = ((msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT, msg.getMessage().getBytes())));
    }
    // ignore the message, it doesnt have the flag set
    if (process)
        super.messageReceived(msg);
    else if (log.isDebugEnabled())
        log.debug("Received a failure detector packet:" + msg);
}

18 Source : 748.java
with MIT License
from masud-technope

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    } catch (ChannelException cx) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for (int i = 0; i < mbrs.length; i++) {
            if (mbrs[i].getCause() != null && (!(mbrs[i].getCause() instanceof RemoteProcessException))) {
                this.memberDisappeared(mbrs[i].getMember());
            }
        }
        throw cx;
    }
}

18 Source : 449.java
with MIT License
from masud-technope

@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    long start = System.currentTimeMillis();
    this.setUdpBased((msg.getOptions() & Channel.SEND_OPTIONS_UDP) == Channel.SEND_OPTIONS_UDP);
    byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
    NioSender[] senders = setupForSend(destination);
    connect(senders);
    setData(senders, data);
    int remaining = senders.length;
    ChannelException cx = null;
    try {
        // loop until complete, an error happens, or we timeout
        long delta = System.currentTimeMillis() - start;
        boolean waitForAck = (Channel.SEND_OPTIONS_USE_ACK & msg.getOptions()) == Channel.SEND_OPTIONS_USE_ACK;
        while ((remaining > 0) && (delta < getTimeout())) {
            try {
                remaining -= doLoop(selectTimeout, getMaxRetryAttempts(), waitForAck, msg);
            } catch (Exception x) {
                if (log.isTraceEnabled())
                    log.trace("Error sending message", x);
                int faulty = (cx == null) ? 0 : cx.getFaultyMembers().length;
                if (cx == null) {
                    if (x instanceof ChannelException)
                        cx = (ChannelException) x;
                    else
                        cx = new ChannelException("Parallel NIO send failed.", x);
                } else {
                    if (x instanceof ChannelException)
                        cx.addFaultyMember(((ChannelException) x).getFaultyMembers());
                }
                if (faulty < cx.getFaultyMembers().length)
                    remaining -= (cx.getFaultyMembers().length - faulty);
            }
            // bail out if all remaining senders are failing
            if (cx != null && cx.getFaultyMembers().length == remaining)
                throw cx;
            delta = System.currentTimeMillis() - start;
        }
        if (remaining > 0) {
            // timeout has occurred
            ChannelException cxtimeout = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            if (cx == null)
                cx = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            for (int i = 0; i < senders.length; i++) {
                if (!senders[i].isComplete())
                    cx.addFaultyMember(senders[i].getDestination(), cxtimeout);
            }
            throw cx;
        } else if (cx != null) {
            // there was an error
            throw cx;
        }
    } catch (Exception x) {
        try {
            this.disconnect();
        } catch (Exception e) {
        }
        if (x instanceof ChannelException)
            throw (ChannelException) x;
        else
            throw new ChannelException(x);
    }
}

18 Source : 295.java
with MIT License
from masud-technope

@Override
public void messageReceived(ChannelMessage msg) {
    // catch incoming
    boolean process = true;
    if (okToProcess(msg.getOptions())) {
        // check to see if it is a ping message, if so, process = false
        process = ((msg.getMessage().getLength() != TCP_PING_DATA.length) || (!Arrays.equals(TCP_PING_DATA, msg.getMessage().getBytes())));
    }
    // ignore the message, it doesnt have the flag set
    if (process)
        super.messageReceived(msg);
    else if (log.isDebugEnabled())
        log.debug("Received a TCP ping packet:" + msg);
}

18 Source : ParallelNioSender.java
with Apache License 2.0
from how2j

@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    long start = System.currentTimeMillis();
    this.setUdpBased((msg.getOptions() & Channel.SEND_OPTIONS_UDP) == Channel.SEND_OPTIONS_UDP);
    byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
    NioSender[] senders = setupForSend(destination);
    connect(senders);
    setData(senders, data);
    int remaining = senders.length;
    ChannelException cx = null;
    try {
        // loop until complete, an error happens, or we timeout
        long delta = System.currentTimeMillis() - start;
        boolean waitForAck = (Channel.SEND_OPTIONS_USE_ACK & msg.getOptions()) == Channel.SEND_OPTIONS_USE_ACK;
        while ((remaining > 0) && (delta < getTimeout())) {
            try {
                remaining -= doLoop(selectTimeout, getMaxRetryAttempts(), waitForAck, msg);
            } catch (Exception x) {
                if (log.isTraceEnabled())
                    log.trace("Error sending message", x);
                int faulty = (cx == null) ? 0 : cx.getFaultyMembers().length;
                if (cx == null) {
                    if (x instanceof ChannelException)
                        cx = (ChannelException) x;
                    else
                        cx = new ChannelException("Parallel NIO send failed.", x);
                } else {
                    if (x instanceof ChannelException)
                        cx.addFaultyMember(((ChannelException) x).getFaultyMembers());
                }
                // count down the remaining on an error
                if (faulty < cx.getFaultyMembers().length)
                    remaining -= (cx.getFaultyMembers().length - faulty);
            }
            // bail out if all remaining senders are failing
            if (cx != null && cx.getFaultyMembers().length == remaining)
                throw cx;
            delta = System.currentTimeMillis() - start;
        }
        if (remaining > 0) {
            // timeout has occurred
            ChannelException cxtimeout = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            if (cx == null)
                cx = new ChannelException("Operation has timed out(" + getTimeout() + " ms.).");
            for (int i = 0; i < senders.length; i++) {
                if (!senders[i].isComplete())
                    cx.addFaultyMember(senders[i].getDestination(), cxtimeout);
            }
            throw cx;
        } else if (cx != null) {
            // there was an error
            throw cx;
        }
    } catch (Exception x) {
        try {
            this.disconnect();
        } catch (Exception e) {
        /* Ignore */
        }
        if (x instanceof ChannelException)
            throw (ChannelException) x;
        else
            throw new ChannelException(x);
    }
}

18 Source : LinkObject.java
with Apache License 2.0
from how2j

/**
 * The clreplaced <b>LinkObject</b> implements an element for a linked list,
 * consisting of a general data object and a pointer to the next element.
 *
 * @author Rainer Jung
 * @author Peter Rossbach
 * @author Filip Hanik
 */
public clreplaced LinkObject {

    private ChannelMessage msg;

    private LinkObject next;

    private byte[] key;

    private Member[] destination;

    private InterceptorPayload payload;

    /**
     * Construct a new element from the data object. Sets the pointer to null.
     *
     * @param msg
     *            the message
     * @param destination
     *            TBA
     * @param payload
     *            The data object.
     */
    public LinkObject(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
        this.msg = msg;
        this.next = null;
        this.key = msg.getUniqueId();
        this.payload = payload;
        this.destination = destination;
    }

    /**
     * Set the next element.
     *
     * @param next
     *            The next element.
     */
    public void append(LinkObject next) {
        this.next = next;
    }

    /**
     * Get the next element.
     *
     * @return The next element.
     */
    public LinkObject next() {
        return next;
    }

    public void setNext(LinkObject next) {
        this.next = next;
    }

    /**
     * Get the data object from the element.
     *
     * @return The data object from the element.
     */
    public ChannelMessage data() {
        return msg;
    }

    /**
     * Get the unique message id
     *
     * @return the unique message id
     */
    public byte[] getKey() {
        return key;
    }

    public ErrorHandler getHandler() {
        return payload != null ? payload.getErrorHandler() : null;
    }

    public InterceptorPayload getPayload() {
        return payload;
    }

    public Member[] getDestination() {
        return destination;
    }
}

18 Source : TcpFailureDetector.java
with Apache License 2.0
from how2j

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    } catch (ChannelException cx) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for (int i = 0; i < mbrs.length; i++) {
            if (mbrs[i].getCause() != null && (!(mbrs[i].getCause() instanceof RemoteProcessException))) {
                // RemoteProcessException's
                // are
                // ok
                this.memberDisappeared(mbrs[i].getMember());
            }
        // end if
        }
        // for
        throw cx;
    }
}

18 Source : ChannelCoordinator.java
with Apache License 2.0
from how2j

/**
 * Send a message to one or more members in the cluster
 *
 * @param destination
 *            Member[] - the destinations, null or zero length means all
 * @param msg
 *            ClusterMessage - the message to send
 * @param payload
 *            TBA
 */
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (destination == null)
        destination = membershipService.getMembers();
    if ((msg.getOptions() & Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) {
        membershipService.broadcast(msg);
    } else {
        clusterSender.sendMessage(msg, destination);
    }
    if (Logs.MESSAGES.isTraceEnabled()) {
        Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " to " + Arrays.toNameString(destination));
    }
}

18 Source : PooledParallelSender.java
with GNU General Public License v3.0
from guang19

@Override
public void sendMessage(Member[] destination, ChannelMessage message) throws ChannelException {
    if (!isConnected()) {
        throw new ChannelException(sm.getString("pooledParallelSender.sender.disconnected"));
    }
    ParallelNioSender sender = (ParallelNioSender) getSender();
    if (sender == null) {
        ChannelException cx = new ChannelException(sm.getString("pooledParallelSender.unable.retrieveSender.timeout", Long.toString(getMaxWait())));
        for (int i = 0; i < destination.length; i++) cx.addFaultyMember(destination[i], new NullPointerException(sm.getString("pooledParallelSender.unable.retrieveSender")));
        throw cx;
    } else {
        try {
            if (!sender.isConnected())
                sender.connect();
            sender.sendMessage(destination, message);
            sender.keepalive();
        } catch (ChannelException x) {
            sender.disconnect();
            throw x;
        } finally {
            returnSender(sender);
        }
    }
}

18 Source : ParallelNioSender.java
with GNU General Public License v3.0
from guang19

@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    long start = System.currentTimeMillis();
    this.setUdpBased((msg.getOptions() & Channel.SEND_OPTIONS_UDP) == Channel.SEND_OPTIONS_UDP);
    byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
    NioSender[] senders = setupForSend(destination);
    connect(senders);
    setData(senders, data);
    int remaining = senders.length;
    ChannelException cx = null;
    try {
        // loop until complete, an error happens, or we timeout
        long delta = System.currentTimeMillis() - start;
        boolean waitForAck = (Channel.SEND_OPTIONS_USE_ACK & msg.getOptions()) == Channel.SEND_OPTIONS_USE_ACK;
        while ((remaining > 0) && (delta < getTimeout())) {
            try {
                SendResult result = doLoop(selectTimeout, getMaxRetryAttempts(), waitForAck, msg);
                remaining -= result.getCompleted();
                if (result.getFailed() != null) {
                    remaining -= result.getFailed().getFaultyMembers().length;
                    if (cx == null)
                        cx = result.getFailed();
                    else
                        cx.addFaultyMember(result.getFailed().getFaultyMembers());
                }
            } catch (Exception x) {
                if (log.isTraceEnabled())
                    log.trace("Error sending message", x);
                if (cx == null) {
                    if (x instanceof ChannelException)
                        cx = (ChannelException) x;
                    else
                        cx = new ChannelException(sm.getString("parallelNioSender.send.failed"), x);
                }
                for (int i = 0; i < senders.length; i++) {
                    if (!senders[i].isComplete()) {
                        cx.addFaultyMember(senders[i].getDestination(), x);
                    }
                }
                throw cx;
            }
            delta = System.currentTimeMillis() - start;
        }
        if (remaining > 0) {
            // timeout has occurred
            ChannelException cxtimeout = new ChannelException(sm.getString("parallelNioSender.operation.timedout", Long.toString(getTimeout())));
            if (cx == null) {
                cx = new ChannelException(sm.getString("parallelNioSender.operation.timedout", Long.toString(getTimeout())));
            }
            for (int i = 0; i < senders.length; i++) {
                if (!senders[i].isComplete()) {
                    cx.addFaultyMember(senders[i].getDestination(), cxtimeout);
                }
            }
            throw cx;
        } else if (cx != null) {
            // there was an error
            throw cx;
        }
    } catch (Exception x) {
        try {
            this.disconnect();
        } catch (Exception e) {
        // Ignore
        }
        if (x instanceof ChannelException)
            throw (ChannelException) x;
        else
            throw new ChannelException(x);
    }
}

18 Source : ThroughputInterceptor.java
with GNU General Public License v3.0
from guang19

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (access.addAndGet(1) == 1)
        txStart = System.currentTimeMillis();
    long bytes = XByteBuffer.getDataPackageLength(((ChannelData) msg).getDataPackageLength());
    try {
        super.sendMessage(destination, msg, payload);
    } catch (ChannelException x) {
        msgTxErr.addAndGet(1);
        if (access.get() == 1)
            access.addAndGet(-1);
        throw x;
    }
    mbTx += (bytes * destination.length) / (1024d * 1024d);
    mbAppTx += bytes / (1024d * 1024d);
    if (access.addAndGet(-1) == 0) {
        long stop = System.currentTimeMillis();
        timeTx += (stop - txStart) / 1000d;
        if ((msgTxCnt.get() / (double) interval) >= lastCnt) {
            lastCnt++;
            report(timeTx);
        }
    }
    msgTxCnt.addAndGet(1);
}

18 Source : StaticMembershipInterceptor.java
with GNU General Public License v3.0
from guang19

@Override
public void messageReceived(ChannelMessage msg) {
    if (msg.getMessage().getLength() == MEMBER_START.length && Arrays.equals(MEMBER_START, msg.getMessage().getBytes())) {
        // receive member start
        Member member = getMember(msg.getAddress());
        if (member != null) {
            super.memberAdded(member);
        }
    } else if (msg.getMessage().getLength() == MEMBER_STOP.length && Arrays.equals(MEMBER_STOP, msg.getMessage().getBytes())) {
        // receive member shutdown
        Member member = getMember(msg.getAddress());
        if (member != null) {
            try {
                member.setCommand(Member.SHUTDOWN_PAYLOAD);
                super.memberDisappeared(member);
            } finally {
                member.setCommand(new byte[0]);
            }
        }
    } else {
        super.messageReceived(msg);
    }
}

18 Source : NonBlockingCoordinator.java
with GNU General Public License v3.0
from guang19

@Override
public void messageReceived(ChannelMessage msg) {
    if (Arrays.contains(msg.getMessage().getBytesDirect(), 0, COORD_ALIVE, 0, COORD_ALIVE.length)) {
        // ignore message, its an alive message
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE, this, "Alive Message"));
    } else if (Arrays.contains(msg.getMessage().getBytesDirect(), 0, COORD_HEADER, 0, COORD_HEADER.length)) {
        try {
            CoordinationMessage cmsg = new CoordinationMessage(msg.getMessage());
            Member[] cmbr = cmsg.getMembers();
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE, this, "Coord Msg Arrived(" + Arrays.toNameString(cmbr) + ")"));
            processCoordMessage(cmsg);
        } catch (ChannelException x) {
            log.error(sm.getString("nonBlockingCoordinator.processCoordinationMessage.failed"), x);
        }
    } else {
        super.messageReceived(msg);
    }
}

18 Source : MessageDispatchInterceptor.java
with GNU General Public License v3.0
from guang19

public boolean addToQueue(final ChannelMessage msg, final Member[] destination, final InterceptorPayload payload) {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            sendAsyncData(msg, destination, payload);
        }
    };
    executor.execute(r);
    return true;
}

18 Source : GzipInterceptor.java
with GNU General Public License v3.0
from guang19

@Override
public void messageReceived(ChannelMessage msg) {
    try {
        byte[] data = msg.getMessage().getBytes();
        if ((msg.getOptions() & getOptionFlag()) > 0) {
            if (statsEnabled) {
                countCompressedRX.incrementAndGet();
                compressedSizeRX.addAndGet(data.length);
            }
            // Message was compressed
            data = decompress(data);
        } else if (statsEnabled) {
            countUncompressedRX.incrementAndGet();
            uncompressedSizeRX.addAndGet(data.length);
        }
        if (statsEnabled) {
            sizeRX.addAndGet(data.length);
        }
        msg.getMessage().trim(msg.getMessage().getLength());
        msg.getMessage().append(data, 0, data.length);
        super.messageReceived(msg);
        int currentCount = count.incrementAndGet();
        if (statsEnabled && interval > 0 && currentCount % interval == 0) {
            report();
        }
    } catch (IOException x) {
        log.error(sm.getString("gzipInterceptor.decompress.failed"), x);
    }
}

18 Source : EncryptInterceptor.java
with GNU General Public License v3.0
from guang19

@Override
public void messageReceived(ChannelMessage msg) {
    try {
        byte[] data = msg.getMessage().getBytes();
        data = encryptionManager.decrypt(data);
        XByteBuffer xbb = msg.getMessage();
        // Completely replace the message with the decrypted one
        xbb.clear();
        xbb.append(data, 0, data.length);
        super.messageReceived(msg);
    } catch (GeneralSecurityException gse) {
        log.error(sm.getString("encryptInterceptor.decrypt.failed"), gse);
    }
}

18 Source : GroupChannel.java
with GNU General Public License v3.0
from guang19

/**
 * Callback from the interceptor stack. <br>
 * When a message is received from a remote node, this method will be
 * invoked by the previous interceptor.<br>
 * This method can also be used to send a message to other components
 * within the same application, but its an extreme case, and you're probably
 * better off doing that logic between the applications itself.
 * @param msg ChannelMessage
 */
@Override
public void messageReceived(ChannelMessage msg) {
    if (msg == null)
        return;
    try {
        if (Logs.MESSAGES.isTraceEnabled()) {
            Logs.MESSAGES.trace("GroupChannel - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " from " + msg.getAddress().getName());
        }
        Serializable fwd = null;
        if ((msg.getOptions() & SEND_OPTIONS_BYTE_MESSAGE) == SEND_OPTIONS_BYTE_MESSAGE) {
            fwd = new ByteMessage(msg.getMessage().getBytes());
        } else {
            try {
                fwd = XByteBuffer.deserialize(msg.getMessage().getBytesDirect(), 0, msg.getMessage().getLength());
            } catch (Exception sx) {
                log.error(sm.getString("groupChannel.unable.deserialize", msg), sx);
                return;
            }
        }
        if (Logs.MESSAGES.isTraceEnabled()) {
            Logs.MESSAGES.trace("GroupChannel - Receive Message:" + new UniqueId(msg.getUniqueId()) + " is " + fwd);
        }
        // get the actual member with the correct alive time
        Member source = msg.getAddress();
        boolean rx = false;
        boolean delivered = false;
        for (int i = 0; i < channelListeners.size(); i++) {
            ChannelListener channelListener = channelListeners.get(i);
            if (channelListener != null && channelListener.accept(fwd, source)) {
                channelListener.messageReceived(fwd, source);
                delivered = true;
                // if the message was accepted by an RPC channel, that channel
                // is responsible for returning the reply, otherwise we send an absence reply
                if (channelListener instanceof RpcChannel)
                    rx = true;
            }
        }
        // for
        if ((!rx) && (fwd instanceof RpcMessage)) {
            // if we have a message that requires a response,
            // but none was given, send back an immediate one
            sendNoRpcChannelReply((RpcMessage) fwd, source);
        }
        if (Logs.MESSAGES.isTraceEnabled()) {
            Logs.MESSAGES.trace("GroupChannel delivered[" + delivered + "] id:" + new UniqueId(msg.getUniqueId()));
        }
    } catch (Exception x) {
        // this could be the channel listener throwing an exception, we should log it
        // as a warning.
        if (log.isWarnEnabled())
            log.warn(sm.getString("groupChannel.receiving.error"), x);
        throw new RemoteProcessException(sm.getString("groupChannel.receiving.error"), x);
    }
}

See More Examples