本文整理汇总了Java中com.alibaba.jstorm.callback.Callback类的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Callback类属于com.alibaba.jstorm.callback包,在下文中一共展示了Callback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
@Override
public <T> Object execute(T... args) {
// TODO Auto-generated method stub
String topologyName = (String) args[0];
try {
if (isLocal) {
System.out.println("REACH: " + drpc.execute(topologyName, "aaa"));
System.out.println("REACH: " + drpc.execute(topologyName, "foo.com/blog/1"));
System.out.println("REACH: " + drpc.execute(topologyName, "engineering.twitter.com/blog/5"));
} else {
Callback callback = new JStormHelper.CheckAckedFail(conf);
callback.execute(args);
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Failed to run drpc action");
}
return null;
}
示例2: runTopologyLocally
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public static void runTopologyLocally(StormTopology topology, String topologyName, Config conf,
int runtimeInSeconds, Callback callback) throws Exception {
LocalCluster cluster = new LocalCluster();
cluster.submitTopology(topologyName, conf, topology);
if (runtimeInSeconds < 120) {
JStormUtils.sleepMs(120 * 1000);
} else {
JStormUtils.sleepMs(runtimeInSeconds * 1000);
}
if (callback != null) {
callback.execute(topologyName);
}
cluster.killTopology(topologyName);
cluster.shutdown();
}
示例3: runTopologyRemotely
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public static void runTopologyRemotely(StormTopology topology, String topologyName, Config conf,
int runtimeInSeconds, Callback callback) throws Exception {
if (conf.get(Config.TOPOLOGY_WORKERS) == null) {
conf.setNumWorkers(3);
}
StormSubmitter.submitTopology(topologyName, conf, topology);
if (JStormUtils.parseBoolean(conf.get("RUN_LONG_TIME"), false)) {
LOG.info(topologyName + " will run long time");
return;
}
if (runtimeInSeconds < 120) {
JStormUtils.sleepMs(120 * 1000);
} else {
JStormUtils.sleepMs(runtimeInSeconds * 1000);
}
if (callback != null) {
callback.execute(topologyName);
}
killTopology(conf, topologyName);
}
示例4: initFollowerThread
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
@SuppressWarnings("unused")
private void initFollowerThread(Map conf) {
// when this nimbus become leader, we will execute this callback, to init some necessary data/thread
Callback leaderCallback = new Callback() {
public <T> Object execute(T... args) {
try {
init(data.getConf());
} catch (Exception e) {
LOG.error("Nimbus init error after becoming a leader", e);
JStormUtils.halt_process(0, "Failed to init nimbus");
}
return null;
}
};
follower = new FollowerRunnable(data, 5000, leaderCallback);
Thread thread = new Thread(follower);
thread.setDaemon(true);
thread.start();
LOG.info("Successfully init Follower thread");
}
示例5: handlerCallback
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
private void handlerCallback() {
if (_callbacks != null) {
synchronized (_callbackLock) {
if (_callbacks != null) {
Iterator<Callback> itr = _callbacks.iterator();
while (itr.hasNext()) {
Callback cb = itr.next();
if ((boolean) cb.execute(this)) {
itr.remove();
}
}
if (_callbacks.size() == 0) {
_callbacks = null;
}
}
}
}
}
示例6: execute
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
@Override
public <T> Object execute(T... args) {
// TODO Auto-generated method stub
String topologyName = (String) args[0];
try {
if (isLocal) {
for (int i = 0; i < 100; i++) {
System.out.println("DRPC RESULT: " + drpc.execute("words", "cat the dog jumped"));
Thread.sleep(1000);
}
} else {
Callback callback = new JStormHelper.CheckAckedFail(conf);
callback.execute(args);
// Map conf = Utils.readStormConfig();
// "foo.com/blog/1" "engineering.twitter.com/blog/5"
// DRPCClient client = new DRPCClient(conf, "localhost",
// 4772);
// String result = client.execute((String)args[0],
// "tech.backtype.com/blog/123");
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Failed to run drpc action");
}
return null;
}
示例7: execute
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
@Override
public <T> Object execute(T... args) {
// TODO Auto-generated method stub
try {
if (isLocal) {
for (int i = 0; i < 100; i++) {
System.out.println("DRPC RESULT: " + drpc.execute("words", "CAT THE DOG JUMPED"));
Thread.sleep(1000);
}
} else {
Callback callback = new JStormHelper.CheckAckedFail(conf);
callback.execute(args);
// Map conf = Utils.readStormConfig();
// "foo.com/blog/1" "engineering.twitter.com/blog/5"
// DRPCClient client = new DRPCClient(conf, "localhost",
// 4772);
// String result = client.execute((String)args[0],
// "tech.backtype.com/blog/123");
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Failed to run drpc action");
}
return null;
}
示例8: runTopology
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public static void runTopology(StormTopology topology, String topologyName, Config conf, int runtimeInSeconds,
Callback callback, boolean isLocal) throws Exception {
if (isLocal) {
runTopologyLocally(topology, topologyName, conf, runtimeInSeconds, callback);
} else {
runTopologyRemotely(topology, topologyName, conf, runtimeInSeconds, callback);
}
}
示例9: publishCallback
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public void publishCallback(Callback cb) {
if (cb != null) {
synchronized (_callbackLock) {
if (_callbacks == null) {
_callbacks = new ArrayList<>();
}
_callbacks.add(cb);
}
}
}
示例10: transitionLock
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
/**
* Changing status
*
* @param topologyId
* @param errorOnNTransition
* if it is true, failure will throw exception
* @param args
* -- will be used in the status changing callback
*
*/
public <T> void transitionLock(String topologyid,
boolean errorOnNoTransition, StatusType changeStatus, T... args)
throws Exception {
// get ZK's topology node's data, which is StormBase
StormBase stormbase = data.getStormClusterState().storm_base(
topologyid, null);
if (stormbase == null) {
LOG.error("Cannot apply event changing status "
+ changeStatus.getStatus() + " to " + topologyid
+ " because failed to get StormBase from ZK");
return;
}
StormStatus currentStatus = stormbase.getStatus();
if (currentStatus == null) {
LOG.error("Cannot apply event changing status "
+ changeStatus.getStatus() + " to " + topologyid
+ " because topologyStatus is null in ZK");
return;
}
// <currentStatus, Map<changingStatus, callback>>
Map<StatusType, Map<StatusType, Callback>> callbackMap = stateTransitions(
topologyid, currentStatus);
// get current changingCallbacks
Map<StatusType, Callback> changingCallbacks = callbackMap
.get(currentStatus.getStatusType());
if (changingCallbacks == null
|| changingCallbacks.containsKey(changeStatus) == false
|| changingCallbacks.get(changeStatus) == null) {
String msg = "No transition for event: changing status:"
+ changeStatus.getStatus() + ", current status: "
+ currentStatus.getStatusType() + " topology-id: "
+ topologyid;
LOG.info(msg);
if (errorOnNoTransition) {
throw new RuntimeException(msg);
}
return;
}
Callback callback = changingCallbacks.get(changeStatus);
Object obj = callback.execute(args);
if (obj != null && obj instanceof StormStatus) {
StormStatus newStatus = (StormStatus) obj;
// update status to ZK
data.getStormClusterState().update_storm(topologyid, newStatus);
LOG.info("Successfully updated " + topologyid + " as status "
+ newStatus);
}
LOG.info("Successfully apply event changing status "
+ changeStatus.getStatus() + " to " + topologyid);
return;
}
示例11: transitionLock
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
/**
* Changing status
*
* @param args -- will be used in the status changing callback
*/
public <T> void transitionLock(String topologyid, boolean errorOnNoTransition, StatusType changeStatus, T... args) throws Exception {
// get ZK's topology node's data, which is StormBase
StormBase stormbase = data.getStormClusterState().storm_base(topologyid, null);
if (stormbase == null) {
LOG.error("Cannot apply event changing status " + changeStatus.getStatus() + " to " + topologyid + " because failed to get StormBase from ZK");
return;
}
StormStatus currentStatus = stormbase.getStatus();
if (currentStatus == null) {
LOG.error("Cannot apply event changing status " + changeStatus.getStatus() + " to " + topologyid + " because topologyStatus is null in ZK");
return;
}
// <currentStatus, Map<changingStatus, callback>>
Map<StatusType, Map<StatusType, Callback>> callbackMap = stateTransitions(topologyid, currentStatus);
// get current changingCallbacks
Map<StatusType, Callback> changingCallbacks = callbackMap.get(currentStatus.getStatusType());
if (changingCallbacks == null || changingCallbacks.containsKey(changeStatus) == false || changingCallbacks.get(changeStatus) == null) {
String msg =
"No transition for event: changing status:" + changeStatus.getStatus() + ", current status: " + currentStatus.getStatusType()
+ " topology-id: " + topologyid;
LOG.info(msg);
if (errorOnNoTransition) {
throw new RuntimeException(msg);
}
return;
}
Callback callback = changingCallbacks.get(changeStatus);
Object obj = callback.execute(args);
if (obj != null && obj instanceof StormStatus) {
StormStatus newStatus = (StormStatus) obj;
// update status to ZK
data.getStormClusterState().update_storm(topologyid, newStatus);
LOG.info("Successfully updated " + topologyid + " as status " + newStatus);
}
LOG.info("Successfully apply event changing status " + changeStatus.getStatus() + " to " + topologyid);
return;
}
示例12: getCallback
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public Callback getCallback() {
return callback;
}
示例13: setCallback
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
public void setCallback(Callback callback) {
this.callback = callback;
}
示例14: execute
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
@Override
public <T> Object execute(T... args) {
// TODO Auto-generated method stub
topologyName = (String) args[0];
if (isLocal == true) {
Callback callback = new JStormHelper.CheckAckedFail(conf);
callback.execute(args);
return null;
}
verifyAssignment();
verifyNumber();
return null;
}
示例15: transitionLock
import com.alibaba.jstorm.callback.Callback; //导入依赖的package包/类
/**
* Changing status
*
* @param args -- will be used in the status changing callback
*/
public <T> void transitionLock(String topologyId, boolean errorOnNoTransition, StatusType changeStatus, T... args)
throws Exception {
// get ZK's topology node's data, which is StormBase
StormBase stormbase = data.getStormClusterState().storm_base(topologyId, null);
if (stormbase == null) {
LOG.error("Cannot apply event: changing status " + topologyId + " -> " + changeStatus.getStatus() +
", cause: failed to get StormBase from ZK");
return;
}
StormStatus currentStatus = stormbase.getStatus();
if (currentStatus == null) {
LOG.error("Cannot apply event: changing status " + topologyId + " -> " + changeStatus.getStatus() +
", cause: topologyStatus is null in ZK");
return;
}
// <currentStatus, Map<changingStatus, callback>>
Map<StatusType, Map<StatusType, Callback>> callbackMap = stateTransitions(topologyId, currentStatus);
// get current changingCallbacks
Map<StatusType, Callback> changingCallbacks = callbackMap.get(currentStatus.getStatusType());
if (changingCallbacks == null || !changingCallbacks.containsKey(changeStatus) ||
changingCallbacks.get(changeStatus) == null) {
String msg = "No transition for event: changing status:" + changeStatus.getStatus() +
", current status: " + currentStatus.getStatusType() + ", topology-id: " + topologyId;
LOG.info(msg);
if (errorOnNoTransition) {
throw new RuntimeException(msg);
}
return;
}
Callback callback = changingCallbacks.get(changeStatus);
Object obj = callback.execute(args);
if (obj != null && obj instanceof StormStatus) {
StormStatus newStatus = (StormStatus) obj;
// update status to ZK
data.getStormClusterState().update_storm(topologyId, newStatus);
LOG.info("Successfully updated " + topologyId + " to status " + newStatus);
}
LOG.info("Successfully apply event: changing status " + topologyId + " -> " + changeStatus.getStatus());
}