use of backtype.storm.messaging.TaskMessage in project storm by nathanmarz.
the class MessageBatch method remove.
void remove(Object obj) {
if (obj == null)
return;
if (obj instanceof TaskMessage) {
TaskMessage msg = (TaskMessage) obj;
msgs.remove(msg);
encoded_length -= msgEncodeLength(msg);
return;
}
if (obj instanceof ControlMessage) {
ControlMessage msg = (ControlMessage) obj;
msgs.remove(msg);
encoded_length -= msg.encodeLength();
return;
}
}
use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.
the class NettyServer method sendFlowCtrlResp.
private void sendFlowCtrlResp(Channel channel, int taskId) {
//channel.setReadable(false);
// send back backpressure flow control request to source client
ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE + 1);
// 1-> start flow control; 0-> stop flow control
buffer.put((byte) 1);
buffer.putInt(taskId);
TaskMessage flowCtrlMsg = new TaskMessage(TaskMessage.BACK_PRESSURE_REQUEST, 1, buffer.array());
channel.write(flowCtrlMsg);
//LOG.debug("Send flow ctrl resp to address({}) for task-{}", channel.getRemoteAddress().toString(), taskId);
//channel.setReadable(true);
}
use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.
the class VirtualPortCtrlDispatch method handleEvent.
@Override
public void handleEvent(Object event, boolean endOfBatch) throws Exception {
TaskMessage message = (TaskMessage) event;
int task = message.task();
Object tuple = null;
try {
// there might be errors when calling update_topology
tuple = deserialize(message.message(), task);
} catch (Throwable e) {
if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e))
throw new RuntimeException(e);
LOG.warn("serialize msg error", e);
}
DisruptorQueue queue = controlQueues.get(task);
if (queue == null) {
LOG.warn("Received invalid control message for task-{}, Dropping...{} ", task, tuple);
return;
}
if (tuple != null) {
queue.publish(tuple);
}
}
use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.
the class DrainerCtrlRunable method handleEvent.
@Override
public void handleEvent(Object event, boolean endOfBatch) throws Exception {
if (event == null) {
return;
}
ITupleExt tuple = (ITupleExt) event;
int targetTask = tuple.getTargetTaskId();
IConnection conn = getConnection(targetTask);
if (conn != null) {
byte[] tupleMessage = null;
try {
// there might be errors when calling update_topology
tupleMessage = serialize(tuple);
} catch (Throwable e) {
if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e)) {
throw new RuntimeException(e);
} else {
LOG.warn("serialize happened errors!!!", e);
}
}
TaskMessage message = new TaskMessage(TaskMessage.CONTROL_MESSAGE, targetTask, tupleMessage);
conn.sendDirect(message);
}
}
use of backtype.storm.messaging.TaskMessage in project jstorm by alibaba.
the class TransferDrainer method getBundleIterator.
private Iterator<TaskMessage> getBundleIterator(final ArrayList<ArrayList<TaskMessage>> bundle) {
if (null == bundle) {
return null;
}
return new Iterator<TaskMessage>() {
private int offset = 0;
private int size = 0;
{
for (ArrayList<TaskMessage> list : bundle) {
size += list.size();
}
}
private int bundleOffset = 0;
private Iterator<TaskMessage> iter = bundle.get(bundleOffset).iterator();
@Override
public boolean hasNext() {
return offset < size;
}
@Override
public TaskMessage next() {
TaskMessage msg;
if (iter.hasNext()) {
msg = iter.next();
} else {
bundleOffset++;
iter = bundle.get(bundleOffset).iterator();
msg = iter.next();
}
if (null != msg) {
offset++;
}
return msg;
}
@Override
public void remove() {
throw new RuntimeException("not supported");
}
};
}
Aggregations