本文整理匯總了Java中rx.subjects.Subject.asObservable方法的典型用法代碼示例。如果您正苦於以下問題:Java Subject.asObservable方法的具體用法?Java Subject.asObservable怎麽用?Java Subject.asObservable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rx.subjects.Subject
的用法示例。
在下文中一共展示了Subject.asObservable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import rx.subjects.Subject; //導入方法依賴的package包/類
/** @see BinderFactory#create(AgentID, Class) */
@Override
public synchronized GuiceBinder create(final AgentID agentID,
final Class<? extends Agent> agentType) // throws CoalaException
{
final GuiceBinder cached = this.binderCache.get(agentID);
if (cached != null)
{
LOG.warn("UNEXPECTED: re-using binder previously created for agent: "
+ agentID);
return cached;
}
if (getConfig() == null)
{
throw CoalaExceptionFactory.VALUE_NOT_CONFIGURED.createRuntime(
"config",
"use BinderFactory#initialize(BinderFactoryConfig)");
}
final AgentStatusUpdate defaultValue = new AgentStatusUpdate()
{
@Override
public AgentID getAgentID()
{
return agentID;
}
@Override
public AgentStatus<?> getStatus()
{
return BasicAgentStatus.CREATED;
}
@Override
public String toString()
{
return JsonUtil.toJSONString(this);
}
};
final Subject<AgentStatusUpdate, AgentStatusUpdate> behaviorSubject = BehaviorSubject
.create(defaultValue);
this.statusUpdates.filter(new Func1<AgentStatusUpdate, Boolean>()
{
@Override
public Boolean call(final AgentStatusUpdate update)
{
return update.getAgentID().equals(agentID);
}
}).subscribe(behaviorSubject);
final GuiceBinder result = new GuiceBinder(getConfig(), agentID,
agentType, behaviorSubject.asObservable());
this.binderCache.put(agentID, result);
LOG.trace("Cached new binder for agent: " + agentID);
return result;
}
示例2: bootAgent
import rx.subjects.Subject; //導入方法依賴的package包/類
@Schedulable(ADD_PROCESS_MANAGER_AGENT)
protected synchronized Observable<AgentStatusUpdate> bootAgent(
final AgentID agentID, final Class<? extends Agent> agentType,
// final BasicAgentStatus blockSimUntilState,
final Job<?> next) throws Exception
{
if (next == null) // no need to sleep sim, nothing to schedule next
return getBooter().createAgent(agentID, agentType);
final CountDownLatch latch = new CountDownLatch(1);
final Subject<AgentStatusUpdate, AgentStatusUpdate> status = ReplaySubject
.create();
status.subscribe(new Observer<AgentStatusUpdate>()
{
/** */
private boolean success = false;
@Override
public void onNext(final AgentStatusUpdate update)
{
LOG().trace("Got child agent update: " + update);
if (update.getStatus().isFailedStatus())
{
LOG().warn("Child agent failed: " + update.getAgentID());
latch.countDown();
} else if (update.getStatus().isInitializedStatus()// .equals(blockSimUntilState)
)
{
LOG().info(
"Child agent " + agentID
+ " reached unblock status: "
+ update.getStatus());
// first schedule/block, then countdown/yield
getSimulator().schedule(next,
Trigger.createAbsolute(getTime()));
success = true;
latch.countDown(); // yield
}
}
@Override
public void onCompleted()
{
if (success)
return;
LOG().warn(
"Child agent died but never reached blockable status"
+ ", scheduling next job now");
getSimulator()
.schedule(next, Trigger.createAbsolute(getTime()));
latch.countDown();
}
@Override
public void onError(final Throwable e)
{
e.printStackTrace();
}
});
getSimulator().schedule(
ProcedureCall.create(this, this, AWAIT_METHOD_ID, latch,
agentID), Trigger.createAbsolute(getTime()));
getBooter().createAgent(agentID, agentType).subscribe(status);
return status.asObservable();
}