本文整理汇总了Java中org.jetlang.core.Callback类的典型用法代码示例。如果您正苦于以下问题:Java Callback类的具体用法?Java Callback怎么用?Java Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Callback类属于org.jetlang.core包,在下文中一共展示了Callback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HomeWorker
import org.jetlang.core.Callback; //导入依赖的package包/类
public HomeWorker(Fiber fiberThread, int mapId, int homeId, long ownerId) {
this.fiberThread = fiberThread;
this.mapId = mapId;
this.homeId = homeId;
this.ownerUid = ownerId;
//回调方法
Callback<List<NMessage>> callback = new HomeWorkerCallback(this);
//像消息通道注册消息处理观察者
BatchSubscriber<NMessage> batchSubscriber = new BatchSubscriber<NMessage>(this.fiberThread, callback, 10, TimeUnit.MILLISECONDS);
this.messageChannel.subscribe(this.fiberThread, batchSubscriber);
//改变房间状态为玩家准备中
this.status = HomeStatusEnum.PLAYER_READY_DOING;
}
示例2: Service
import org.jetlang.core.Callback; //导入依赖的package包/类
public Service(String name) {
serviceName = name;
Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
fiber.start();
Callback<Packet> sysCtrlCallback = new Callback<Packet>() {
public void onMessage(Packet pkt) {
if(pkt instanceof ControlPacket){
processSysCtrl((ControlPacket) pkt);
}
}
};
subscription = new Subscription(CoreChannel.SYSCTRL, fiber, sysCtrlCallback);
try {
Kernel.getInstance().getStream().subscribe(subscription);
} catch (CommunicationException e) {
System.err.println(e.getMessage());
}
taskRegistry = new FastMap<String, Taskable>();
}
示例3: Log4jService
import org.jetlang.core.Callback; //导入依赖的package包/类
public Log4jService() {
super(Log4jService.class.getSimpleName());
PropertyConfigurator.configure(CFG_FILE);
Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
fiber.start();
Callback<Packet> callback = new Callback<Packet>() {
public void onMessage(Packet packet) {
LogPacket p = (LogPacket) packet;
Logger.getLogger(p.getSource()).log(Level.toLevel(p.getLevel()), p.getMessage());
}
};
subscription = new Subscription(CoreChannel.LOG, fiber, callback);
try {
Kernel.getInstance().getStream().subscribe(subscription);
} catch (CommunicationException e) {
e.printStackTrace();
}
}
示例4: TwitterService
import org.jetlang.core.Callback; //导入依赖的package包/类
public TwitterService(Properties properties) {
super(TwitterService.class.getSimpleName());
tweeter = new Tweeter(properties);
Fiber fiber = Kernel.getInstance().getScheduler().newFiber();
fiber.start();
Callback<Packet> callback = new Callback<Packet>() {
public void onMessage(Packet pkt) {
LogPacket l = (LogPacket) pkt;
if(l.getSource().equals("twitter")) {
tweeter.tweet(l.getMessage());
}
}
};
subscription = new Subscription(CoreChannel.LOG, fiber, callback);
try {
Kernel.getInstance().getStream().subscribe(subscription);
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: ControlTester
import org.jetlang.core.Callback; //导入依赖的package包/类
public ControlTester(){
counter = 0;
setDelay(1000l);
getRequiredDevices().add("localpose");
Callback<Packet> myCbk = new Callback<Packet>(){
@Override
public void onMessage(Packet message) {
if(message instanceof LocalPosePacket){
Kernel.getInstance().getSyslog().debug(this.getClass().getSimpleName() + " received localpose data.");
}
}
};
subscribe(CoreChannel.SYSTEM, myCbk);
}
示例6: Device
import org.jetlang.core.Callback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Device(Backend backend, String type, String channel, long delay) {
super();
setDelay(delay);
if(channel != null){
Callback<Packet> cbk = new Callback<Packet>(){
public void onMessage(Packet pkt) {
if(pkt.getPacketType().equals(device))
driver.request((T) pkt);
}
};
subscribe(channel, cbk);
}
// super(channel, delay);
driver = (HardwareDriver<T>) backend.getDriver(type + "Driver");
if(driver == null) {
Kernel.getInstance().getSyslog().error("Failed to load " + type + " driver.");
}
device = type.toLowerCase();
}
示例7: JetlangPonger
import org.jetlang.core.Callback; //导入依赖的package包/类
/** Creates a JetlangPonger. */
public JetlangPonger(final Fiber _fiber) {
fiber = _fiber;
channel = new MemoryRequestChannel();
final Callback<Request> onReq = new Callback<Request>() {
@Override
public void onMessage(final Request message) {
final Object request = message.getRequest();
if (request instanceof PingRequest) {
final PingRequest ping = (PingRequest) request;
message.reply(ping.processRequest(JetlangPonger.this));
} else {
throw new IllegalStateException(
"Expected PingRequest but got "
+ request.getClass());
}
}
};
fiber.start();
channel.subscribe(fiber, onReq);
}
示例8: ping
import org.jetlang.core.Callback; //导入依赖的package包/类
/** Send a ping, unless we're done, in which case tell caller we are done. */
private void ping(final Request hammerRequest) throws Exception {
final Callback<Integer> onReply = new Callback<Integer>() {
@Override
public void onMessage(final Integer response) {
pongs++;
if (response.intValue() != pongs) {
throw new IllegalStateException("Expected " + pongs
+ " but got " + response);
}
if (pongs < count) {
try {
ping(hammerRequest);
} catch (final Exception e) {
e.printStackTrace();
hammerRequest.reply(pongs);
}
} else {
hammerRequest.reply(pongs);
}
}
};
ponger.ping(pongs, onReply);
}
示例9: hammer
import org.jetlang.core.Callback; //导入依赖的package包/类
/** Tells the pinger to hammer the Ponger. Blocks and returns the result. */
@SuppressWarnings({ "rawtypes", "unchecked" })
public Integer hammer(final JetlangPonger ponger, final int _count)
throws Exception {
final AtomicReference response = new AtomicReference();
final HammerRequest req = new HammerRequest(ponger, _count);
final CountDownLatch done = new CountDownLatch(1);
final Callback onReply = new Callback() {
@Override
public void onMessage(final Object message) {
// TODO Can we safely access the pinger's state from here?!?
response.set(message);
done.countDown();
}
};
AsyncRequest.withOneReply(fiber, channel, req, onReply);
done.await(60, TimeUnit.SECONDS);
return (Integer) response.get();
}
示例10: AsyncProcessor
import org.jetlang.core.Callback; //导入依赖的package包/类
public AsyncProcessor() {
ExecutorService exec = Executors.newCachedThreadPool();
PoolFiberFactory factory = new PoolFiberFactory(exec);
this.fiberThread = factory.create();
//回调方法
Callback<List<NMessage>> callback = new AsyncCallback(this);
//像消息通道注册消息处理观察者
BatchSubscriber<NMessage> batchSubscriber = new BatchSubscriber<NMessage>(this.fiberThread, callback, 30, TimeUnit.MILLISECONDS);
this.messageChannel.subscribe(this.fiberThread, batchSubscriber);
}
示例11: init
import org.jetlang.core.Callback; //导入依赖的package包/类
/**
* 初始化
*/
public void init() {
//回调方法
Callback<List<InvokeFun>> callback = new ClientManagerCallback(this);
//像消息通道注册消息处理观察者
BatchSubscriber<InvokeFun> batchSubscriber = new BatchSubscriber<InvokeFun>(this.fiberThread, callback, 10, TimeUnit.MILLISECONDS);
invokeChannel.subscribe(this.fiberThread, batchSubscriber);
this.fiberThread.start();
}
示例12: JATOAbstractActor
import org.jetlang.core.Callback; //导入依赖的package包/类
public JATOAbstractActor(JATOActorFactory actorFactory, Channel<T> mailbox, Fiber fiber) {
this.actorFactory = actorFactory;
this.mailbox = mailbox;
this.fiber = fiber;
final JATOAbstractActor<T> self = this;
this.callback = new Callback<T>() {
public void onMessage(T t) {
getActorFactory().addInstanceActorToCache(self, self);
self.onReceive(t);
}
};
mailbox.subscribe(fiber, callback);
}
示例13: startCallbackActor
import org.jetlang.core.Callback; //导入依赖的package包/类
public <T> JATOCallbackActor<T> startCallbackActor(Callback<T> callback) {
Fiber fiber = startFiber();
Channel<T> mailbox = new MemoryChannel<T>();
JATOCallbackActor<T> actor = new JATOCallbackActor<T>(this, mailbox, fiber, callback);
return actor;
}
示例14: GoToGoal
import org.jetlang.core.Callback; //导入依赖的package包/类
public GoToGoal(){
setDelay(1000l);
goalX = 0;//Kernel.homeX;
goalY = 0;//Kernel.homeY;
Kernel.getInstance().getSyslog().debug("Going home: " + goalX + ", " + goalY);
Callback<Packet> localPoseCbk = new Callback<Packet>(){
@Override
public void onMessage(Packet pkt) {
// Kernel.getInstance().getSyslog().debug("Got message: " + pkt.getPacketType());
if(pkt.getPacketType().equals(PacketType.LOCAL_POSE)){
try{
float xPos = ((LocalPosePacket) pkt).getPositionX();
float yPos = ((LocalPosePacket) pkt).getPositionY();
float theta = ((LocalPosePacket) pkt).getTheta();
MotorPacket ctrl = calculateControl(xPos, yPos, theta);
publish(CoreChannel.CTRL, ctrl);
} catch(Exception e){
e.printStackTrace();
}
}
}
};
subscribe(CoreChannel.SYSTEM, localPoseCbk);
// zero out motors
publish(CoreChannel.CTRL, new MotorPacket());
}
示例15: JoystickControl
import org.jetlang.core.Callback; //导入依赖的package包/类
public JoystickControl() {
setDelay(200);
Callback<Packet> jsCbk = new Callback<Packet>() {
public void onMessage(Packet message) {
if(message instanceof JoystickPacket) {
jsPkt = (JoystickPacket) message;
//System.out.println("Got joystick!");
}
}
};
subscribe(CoreChannel.SYSTEM, jsCbk);
}