Java Code Examples for backtype.storm.utils.Utils#exceptionCauseIsInstanceOf()

The following examples show how to use backtype.storm.utils.Utils#exceptionCauseIsInstanceOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrainerCtrlRunable.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: VirtualPortCtrlDispatch.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: VirtualPortCtrlDispatch.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
protected Object deserialize(byte[] serMsg, int taskId) {
    try {
        if (serMsg == null) {
            return null;
        }

        if (serMsg.length == 0) {
            return null;
        } else if (serMsg.length == 1) {
            //ignore
            return null;
        }
        Tuple tuple = null;
        // serMsg.length > 1
        KryoTupleDeserializer kryo = atomKryoDeserializer.get();
        if (kryo != null) {
            tuple = kryo.deserialize(serMsg);
        }
        return tuple;
    } catch (Throwable e) {
        if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e))
            throw new RuntimeException(e);
        LOG.error(idStr + " recv thread error " + JStormUtils.toPrintableString(serMsg) + "\n", e);
    }
    return null;
}
 
Example 4
Source File: TaskReceiver.java    From jstorm with Apache License 2.0 5 votes vote down vote up
protected void deserialize(KryoTupleDeserializer deserializer, byte[] serMsg, DisruptorQueue queue) {
    long start = deserializeTimer.getTime();
    try {
        if (serMsg == null || serMsg.length == 0) {
            return;
        }

        if (serMsg.length == 1) {
            byte newStatus = serMsg[0];
            LOG.info("Change task status as " + newStatus);
            taskStatus.setStatus(newStatus);
            return;
        }

        // ser_msg.length > 1
        if (bolt != null && bolt instanceof IProtoBatchBolt) {
            ((IProtoBatchBolt) bolt).protoExecute(this, deserializer, queue, serMsg);
        } else {
            deserializeTuple(deserializer, serMsg, queue);
        }

    } catch (Throwable e) {
        if (Utils.exceptionCauseIsInstanceOf(KryoException.class, e))
            throw new RuntimeException(e);
        if (!taskStatus.isShutdown()) {
            LOG.error(idStr + " recv thread error " + JStormUtils.toPrintableString(serMsg), e);
        }
    } finally {
        if (MetricUtils.metricAccurateCal)
            deserializeTimer.updateTime(start);
    }
}
 
Example 5
Source File: RotatingTransactionalState.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void cleanupBefore(long txid) {
    SortedMap<Long, Object> toDelete = _curr.headMap(txid);
    for(long tx: new HashSet<>(toDelete.keySet())) {
        _curr.remove(tx);
        try {
            _state.delete(txPath(tx));
        } catch(RuntimeException e) {
            // Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since
            // zookeeper reads are eventually consistent.
            if(!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) {
                throw e;
            }
        }
    }
}