@Test public void testServiceManager() { try (final ServiceManager<SomeInterface> manager = new ServiceManager<>(SomeInterface.class);) { manager.start(new TestInfrastructure("testManager", null, null, null)); final SomeInterface retrieved = manager.getAssociatedInstance(typeId); assertEquals(expectedClass, retrieved.getClass()); } assertEquals(locatorCalled, Factory.locatorCalled); }
public T getAssociatedInstance(final String typeId) throws DempsyException { if(LOGGER.isTraceEnabled()) LOGGER.trace("Trying to find " + clazz.getSimpleName() + " associated with the transport \"{}\"", typeId); T ret = null; synchronized(registered) { ret = registered.get(typeId); if(ret == null) { if(LOGGER.isTraceEnabled()) LOGGER.trace(clazz.getSimpleName() + " associated with the id \"{}\" wasn't already registered. Attempting to create one", typeId); ret = makeInstance(typeId); registered.put(typeId, ret); } } return ret; }
Manager { public T getAssociatedInstance(final String typeId) throws DempsyException { if(LOGGER.isTraceEnabled()) LOGGER.trace("Trying to find " + clazz.getSimpleName() + " associated with the transport \"{}\"", typeId); T ret = null; synchronized(registered) { ret = registered.get(typeId); if(ret == null) { if(LOGGER.isTraceEnabled()) LOGGER.trace(clazz.getSimpleName() + " associated with the id \"{}\" wasn't already registered. Attempting to create one", typeId); ret = makeInstance(typeId); registered.put(typeId, ret); } } return ret; } }
Manager { public T getAssociatedInstance(final String typeId) throws DempsyException { if(LOGGER.isTraceEnabled()) LOGGER.trace("Trying to find " + clazz.getSimpleName() + " associated with the transport \"{}\"", typeId); T ret = null; synchronized(registered) { ret = registered.get(typeId); if(ret == null) { if(LOGGER.isTraceEnabled()) LOGGER.trace(clazz.getSimpleName() + " associated with the id \"{}\" wasn't already registered. Attempting to create one", typeId); ret = makeInstance(typeId); registered.put(typeId, ret); } } return ret; } Manager(final Class<T> clazz); }
Manager { public T getAssociatedInstance(final String typeId) throws DempsyException { if(LOGGER.isTraceEnabled()) LOGGER.trace("Trying to find " + clazz.getSimpleName() + " associated with the transport \"{}\"", typeId); T ret = null; synchronized(registered) { ret = registered.get(typeId); if(ret == null) { if(LOGGER.isTraceEnabled()) LOGGER.trace(clazz.getSimpleName() + " associated with the id \"{}\" wasn't already registered. Attempting to create one", typeId); ret = makeInstance(typeId); registered.put(typeId, ret); } } return ret; } Manager(final Class<T> clazz); T getAssociatedInstance(final String typeId); T makeInstance(final String typeId); void register(final String typeId, final T factory); }
Manager { public T getAssociatedInstance(final String typeId) throws DempsyException { if(LOGGER.isTraceEnabled()) LOGGER.trace("Trying to find " + clazz.getSimpleName() + " associated with the transport \"{}\"", typeId); T ret = null; synchronized(registered) { ret = registered.get(typeId); if(ret == null) { if(LOGGER.isTraceEnabled()) LOGGER.trace(clazz.getSimpleName() + " associated with the id \"{}\" wasn't already registered. Attempting to create one", typeId); ret = makeInstance(typeId); registered.put(typeId, ret); } } return ret; } Manager(final Class<T> clazz); T getAssociatedInstance(final String typeId); T makeInstance(final String typeId); void register(final String typeId, final T factory);  }