shared:
@ApplicationScoped
@TunnelToServer
public interface IMyService {
public MyDto someAction();
}
server:
public class MyService implements IMyService {
public MyDto someAction() {
return getDtoFromBackendOrEvenDatabase();
}
}
client:
public class MyServiceStub implements IMyService {
public MyDto someAction() {
// mock implementation without going to server
return new MyDtoBuilder().withValueA(a).withValueB(b).build();
}
}
public class MyClientSession extends AbstractClientSession {
@Override
public void execLoadSession() throws ProcessingException {
if (isClientOnlyMode()) {
registerStubbedServices();
} else {
super.execLoadSession();
}
}
//
// all code below has not yet been (fully) migrated to Neon
//
private void registerStubbedServices() throws ProcessingException {
Object[] stubedServices = StubbedServiceRegistry.getStubbedServices();
registerServices(getBundle(), 500, stubedServices); // I guess I can get rid of getBundle() here
setServiceTunnel(new StubbedServiceTunnel()); // how do I best replace the service tunnel bean?
setDesktop(new Desktop());
}
public static List<ServiceRegistration<?>> registerServices(Bundle bundle, int ranking, Object... services) {
ArrayList<ServiceRegistration<?>> result = new ArrayList<>();
Hashtable<String, Object> initParams = new Hashtable<>();
initParams.put(Constants.SERVICE_RANKING, ranking); // how do I dynamically set the ranking on my services when I register them?
for (Object service : services) {
ServiceRegistration<?> reg = bundle.getBundleContext().registerService(computeServiceNames(service), service, initParams); // I guess I do this using BEANS.getBeanManager().registerClass(), but how do I make sure no proxy is created or if it was already created, how do I replace it?
result.add(reg);
if (Proxy.isProxyClass(service.getClass())) {
// nop
} else if (service instanceof IService) {
((IService) service).initializeService(reg); // I guess I can just skip this, as the services no longer have this method by default
}
}
SERVICES.clearCache(); // is something similar needed on BEANS?
return result;
}
}
/**
* NOP service tunnel
*/
public final class StubbedServiceTunnel implements IClientServiceTunnel {
@Override
public void setServerURL(URL url) {
}
@Override
public Object invokeService(Class<?> serviceInterfaceClass, Method operation, Object[] args) throws ProcessingException {
return null;
}
@Override
public URL getServerURL() {
return null;
}
@Override
public void setClientNotificationPollInterval(long intervallMillis) {
}
@Override
public void setAnalyzeNetworkLatency(boolean b) {
}
@Override
public boolean isAnalyzeNetworkLatency() {
return false;
}
@Override
public long getClientNotificationPollInterval() {
return 0;
}
}