本文整理汇总了Java中xiaofei.library.hermes.HermesService类的典型用法代码示例。如果您正苦于以下问题:Java HermesService类的具体用法?Java HermesService怎么用?Java HermesService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HermesService类属于xiaofei.library.hermes包,在下文中一共展示了HermesService类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHermesConnected
import xiaofei.library.hermes.HermesService; //导入依赖的package包/类
@Override
public void onHermesConnected(Class<? extends HermesService> service) {
// Here something should be paid attention to.
// If we has started MyService in a sub-process and then kill the main process,
// and if we has not set a default uncaught exception handler,
// then the following will happen:
// 1. HermesListener.onHermesDisconnected() is invoked, and an error occurs:
// "Error occurs. Error 2: Service Unavailable: Check whether you have connected Hermes."
// 2. A new main process is created.
// 3. The sub-process where MyService runs will resume the Hermes connection with
// the new main process, and HermesListener.onHermesConnected() is invoked.
// 4. The sub-process crashes in either of the following two ways:
// (1) After getting the instance of IMainService, the GC runs because there is no strong
// reference to the previous IMainService. However, the main process does not
// have the corresponding MainService and thus throw an exception.
// (2) In the previous version, mRemoteApis was set null when the service is disconnected.
// Then a NPE was thrown when the service is reconnected.
/**
Log.v(TAG, "Hermes connected in Process " + Process.myPid());
mRemoteApis.set(Hermes.getInstanceInService(service, IMainService.class));
mRemoteApis.action(new Action<IMainService>() {
@Override
public void call(IMainService o) {
o.register(Process.myPid(), SubService.getInstance());
}
});
*/
IMainService mainService = Hermes.getInstanceInService(service, IMainService.class);
mainService.register(Process.myPid(), SubService.getInstance());
mRemoteApis.set(mainService);
mState = STATE_CONNECTED;
}
示例2: onHermesDisconnected
import xiaofei.library.hermes.HermesService; //导入依赖的package包/类
@Override
public void onHermesDisconnected(Class<? extends HermesService> service) {
// Log.v(TAG, "Hermes disconnected in Process " + Process.myPid());
mState = STATE_DISCONNECTED;
mRemoteApis.action(new Action<IMainService>() {
@Override
public void call(IMainService o) {
o.unregister(Process.myPid());
}
});
// I deleted the statement which assigns null to mRemoteApis.
// Then, if the service is disconnected, the pending events will still be posted
// but this process will not receive them any more.
}