subscriber.java
来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 65 行
JAVA
65 行
/* Subscriber.java * $Id: Subscriber.java,v 2.2 1997-11-19 19:22:41+09 ht Exp $ $Name: alpha5_1-release $ */package com.ibm.acl.kqmlsample.travel;import com.ibm.acl.kqml.*;/** * * * @version $Revision: 2.2 $ $Date: 1997-11-19 19:22:41+09 $ * @author Hajime Tsuchitani */public abstract class Subscriber extends Thread{ private static final String rcsid = "$Id: Subscriber.java,v 2.2 1997-11-19 19:22:41+09 ht Exp $ $Name: alpha5_1-release $"; /** * variable description goes here */ private boolean forever = false; private long timeout; private Conversation conv = null; private Object agent = null; public Subscriber(Conversation conv, Object agent) { this(conv, agent, 0); } public Subscriber(Conversation conv, Object agent, long timeout) { if (timeout == 0) forever = true; this.conv = conv; this.agent = agent; this.timeout = timeout; } public void run() { // wait for result long waitmills = timeout * 1000; long due = System.currentTimeMillis() + waitmills; long left = 0; while (forever || ((left = due - System.currentTimeMillis()) > 0)) { if (forever) conv.getResult().waitFor(); else conv.getResult().waitFor(left); if (conv.getResult().isAvailable()) { ReturnValue rtn = (ReturnValue) conv.getResult().getSubscribedResult(); handleResult(rtn, agent); } } } public abstract boolean handleResult(ReturnValue rtn, Object agent) ;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?