- if (Layer0.class == api)
- return (T) L0;
- if (ServerInformation.class == api)
- return (T) getCachedServerInformation();
- else if (WriteGraphImpl.class == api)
- return (T) writeState.getGraph();
- else if (ClusterBuilder.class == api)
- return (T)new ClusterBuilderImpl(this, (WriteOnlySupport)writeState.getGraph().writeSupport);
- else if (ClusterBuilderFactory.class == api)
- return (T)new ClusterBuilderFactoryImpl(this);
+ synchronized (this) {
+ if (serviceKey1 == api) {
+ return (T) service1;
+ }
+ if (serviceKey2 == api) {
+ // Promote this key
+ Object result = service2;
+ service2 = service1;
+ serviceKey2 = serviceKey1;
+ service1 = result;
+ serviceKey1 = api;
+ return (T)result;
+ }