本文整理汇总了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();
}