Search in sources :

Example 6 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class ThriftDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
    long available = buf.readableBytes();
    if (available < INTEGER_SIZE) {
        return null;
    }
    buf.markReaderIndex();
    int thriftLen = buf.readInt();
    available -= INTEGER_SIZE;
    if (available < thriftLen) {
        // We haven't received the entire object yet, return and wait for more bytes.
        buf.resetReaderIndex();
        return null;
    }
    byte[] serialized = new byte[thriftLen];
    buf.readBytes(serialized, 0, thriftLen);
    HBMessage m = (HBMessage) Utils.thriftDeserialize(HBMessage.class, serialized);
    if (m.get_type() == HBServerMessageType.CONTROL_MESSAGE) {
        ControlMessage cm = ControlMessage.read(m.get_data().get_message_blob());
        return cm;
    } else if (m.get_type() == HBServerMessageType.SASL_MESSAGE_TOKEN) {
        SaslMessageToken sm = SaslMessageToken.read(m.get_data().get_message_blob());
        return sm;
    } else {
        return m;
    }
}
Also used : SaslMessageToken(org.apache.storm.messaging.netty.SaslMessageToken) HBMessage(org.apache.storm.generated.HBMessage) ControlMessage(org.apache.storm.messaging.netty.ControlMessage)

Example 7 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class ThriftEncoder method encodeNettySerializable.

private HBMessage encodeNettySerializable(INettySerializable netty_message, HBServerMessageType mType) {
    HBMessageData message_data = new HBMessageData();
    HBMessage m = new HBMessage();
    try {
        ChannelBuffer cbuffer = netty_message.buffer();
        if (cbuffer.hasArray()) {
            message_data.set_message_blob(cbuffer.array());
        } else {
            byte[] buff = new byte[netty_message.encodeLength()];
            cbuffer.readBytes(buff, 0, netty_message.encodeLength());
            message_data.set_message_blob(buff);
        }
        m.set_type(mType);
        m.set_data(message_data);
        return m;
    } catch (IOException e) {
        LOG.error("Failed to encode NettySerializable: ", e);
        throw new RuntimeException(e);
    }
}
Also used : HBMessageData(org.apache.storm.generated.HBMessageData) IOException(java.io.IOException) HBMessage(org.apache.storm.generated.HBMessage) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 8 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class Pacemaker method getPulse.

private HBMessage getPulse(String path, boolean authenticated) {
    if (authenticated) {
        byte[] details = heartbeats.get(path);
        LOG.debug("Getting Pulse for path [ {} ]...data [ {} ].", path, details);
        meterGetPulseCount.mark();
        if (details != null) {
            meterTotalSentSize.mark(details.length);
        }
        HBPulse hbPulse = new HBPulse();
        hbPulse.set_id(path);
        hbPulse.set_details(details);
        return new HBMessage(HBServerMessageType.GET_PULSE_RESPONSE, HBMessageData.pulse(hbPulse));
    } else {
        return notAuthorized();
    }
}
Also used : HBPulse(org.apache.storm.generated.HBPulse) HBMessage(org.apache.storm.generated.HBMessage)

Example 9 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class Pacemaker method handleMessage.

@Override
public HBMessage handleMessage(HBMessage m, boolean authenticated) {
    HBMessage response = null;
    HBMessageData data = m.get_data();
    switch(m.get_type()) {
        case CREATE_PATH:
            response = createPath(data.get_path());
            break;
        case EXISTS:
            response = pathExists(data.get_path(), authenticated);
            break;
        case SEND_PULSE:
            response = sendPulse(data.get_pulse());
            break;
        case GET_ALL_PULSE_FOR_PATH:
            response = getAllPulseForPath(data.get_path(), authenticated);
            break;
        case GET_ALL_NODES_FOR_PATH:
            response = getAllNodesForPath(data.get_path(), authenticated);
            break;
        case GET_PULSE:
            response = getPulse(data.get_path(), authenticated);
            break;
        case DELETE_PATH:
            response = deletePath(data.get_path());
            break;
        case DELETE_PULSE_ID:
            response = deletePulseId(data.get_path());
            break;
        default:
            LOG.info("Got Unexpected Type: {}", m.get_type());
            break;
    }
    if (response != null)
        response.set_message_id(m.get_message_id());
    return response;
}
Also used : HBMessageData(org.apache.storm.generated.HBMessageData) HBMessage(org.apache.storm.generated.HBMessage)

Example 10 with HBMessage

use of org.apache.storm.generated.HBMessage in project storm by apache.

the class PacemakerClient method send.

public HBMessage send(HBMessage m) throws PacemakerConnectionException {
    LOG.debug("Sending message: {}", m.toString());
    try {
        int next = availableMessageSlots.take();
        synchronized (m) {
            m.set_message_id(next);
            messages[next] = m;
            LOG.debug("Put message in slot: {}", Integer.toString(next));
            do {
                waitUntilReady();
                Channel channel = channelRef.get();
                if (channel != null) {
                    channel.write(m);
                    m.wait(1000);
                }
            } while (messages[next] == m);
        }
        HBMessage ret = messages[next];
        if (ret == null) {
            // This can happen if we lost the connection and subsequently reconnected or timed out.
            send(m);
        }
        messages[next] = null;
        LOG.debug("Got Response: {}", ret);
        return ret;
    } catch (InterruptedException e) {
        LOG.error("PacemakerClient send interrupted: ", e);
        throw new RuntimeException(e);
    }
}
Also used : Channel(org.jboss.netty.channel.Channel) HBMessage(org.apache.storm.generated.HBMessage)

Aggregations

HBMessage (org.apache.storm.generated.HBMessage)22 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 Pacemaker (org.apache.storm.pacemaker.Pacemaker)9 Test (org.junit.Test)9 HBPulse (org.apache.storm.generated.HBPulse)5 HBMessageData (org.apache.storm.generated.HBMessageData)3 ArrayList (java.util.ArrayList)2 ControlMessage (org.apache.storm.messaging.netty.ControlMessage)2 SaslMessageToken (org.apache.storm.messaging.netty.SaslMessageToken)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 HBNodes (org.apache.storm.generated.HBNodes)1 HBServerMessageType (org.apache.storm.generated.HBServerMessageType)1 INettySerializable (org.apache.storm.messaging.netty.INettySerializable)1 Channel (org.jboss.netty.channel.Channel)1