/** * Creates the naming store if not provided by the constructor. * * @param context The start context * @throws StartException If any problems occur creating the context */ public void start(final StartContext context) throws StartException { if(store == null) { final ServiceRegistry serviceRegistry = context.getController().getServiceContainer(); final ServiceName serviceNameBase = context.getController().getName(); final ServiceTarget serviceTarget = context.getChildTarget(); store = readOnly ? new ServiceBasedNamingStore(serviceRegistry, serviceNameBase) : new WritableServiceBasedNamingStore(serviceRegistry, serviceNameBase, serviceTarget); } }
public void rebind(Name name, Object object) throws NamingException { final Object owner = requireOwner(); // re-set the existent binder service injected value final ServiceName bindName = buildServiceName(name); final ServiceController<?> controller = getServiceRegistry().getService(bindName); if (controller == null) { bind(name, object, owner, bindName); } else { final BinderService binderService = (BinderService) controller.getService(); if (owner instanceof ServiceName) { final ServiceName deploymentUnitServiceName = (ServiceName) owner; binderService.acquire(); final RuntimeBindReleaseService.References duBindingReferences = (RuntimeBindReleaseService.References) controller.getServiceContainer().getService(JndiNamingDependencyProcessor.serviceName(deploymentUnitServiceName)).getValue(); duBindingReferences.add(binderService); } binderService.getManagedObjectInjector().setValue(new ImmediateValue(new ImmediateManagedReferenceFactory(object))); } }
public void bind(final Name name, final Object object) throws NamingException { final Object owner = requireOwner(); final ServiceName bindName = buildServiceName(name); bind(name, object, owner, bindName); }
public void unbind(final Name name) throws NamingException { requireOwner(); final ServiceName bindName = buildServiceName(name); final ServiceController<?> controller = getServiceRegistry().getService(bindName); if (controller == null) { throw NamingLogger.ROOT_LOGGER.cannotResolveService(bindName); } controller.setMode(ServiceController.Mode.REMOVE); final StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(controller); try { monitor.awaitStability(); } catch (Exception e) { throw namingException("Failed to unbind [" + bindName + "]", e); } finally { monitor.removeController(controller); } }
@Override public void setup(Map<String, Object> properties) { NamespaceContextSelector.pushCurrentSelector(namespaceSelector); WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName); }
@Override public void reset() { if(namespaceContextSelector != null) { NamespaceContextSelector.popCurrentSelector(); } if(duServiceName != null) { WritableServiceBasedNamingStore.popOwner(); } }
public void rebind(Name name, Object object) throws NamingException { final ServiceName deploymentUnitServiceName = requireOwner(); final ServiceName bindName = buildServiceName(name); try { unbind(name, bindName); } catch (NamingException ignore) { // rebind may fail if there is no existing binding } bind(name, bindName, object, deploymentUnitServiceName); }
@SuppressWarnings("unchecked") public void unbind(final Name name) throws NamingException { final ServiceName deploymentUnitServiceName = requireOwner(); final ServiceName bindName = buildServiceName(name); // do the unbinding unbind(name, bindName); // remove the service name from runtime bindings management service final Set<ServiceName> duBindingReferences = (Set<ServiceName>) getServiceRegistry().getService(JndiNamingDependencyProcessor.serviceName(deploymentUnitServiceName)).getValue(); duBindingReferences.remove(bindName); }
@SuppressWarnings("unchecked") private void bind(final Name name, final ServiceName bindName, final Object object, final ServiceName deploymentUnitServiceName) throws NamingException { try { final BinderService binderService = new BinderService(name.toString()); final BindListener listener = new BindListener(); final ServiceBuilder<?> builder = serviceTarget.addService(bindName, binderService) .addDependency(getServiceNameBase(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()) .addInjection(binderService.getManagedObjectInjector(), new ValueManagedReferenceFactory(new ImmediateValue<Object>(object))) .setInitialMode(ServiceController.Mode.ACTIVE) .addListener(listener); builder.install(); listener.await(); binderService.acquire(); // add the service name to runtime bindings management service, which on stop releases the services. final Set<ServiceName> duBindingReferences = (Set<ServiceName>) getServiceRegistry().getService(JndiNamingDependencyProcessor.serviceName(deploymentUnitServiceName)).getValue(); duBindingReferences.add(bindName); } catch (Exception e) { throw namingException("Failed to bind [" + object + "] at location [" + bindName + "]", e); } }
public Context createSubcontext(final Name name) throws NamingException { requireOwner(); if (isLastComponentEmpty(name)) { throw NamingLogger.ROOT_LOGGER.emptyNameNotAllowed(); } return new NamingContext(name, WritableServiceBasedNamingStore.this, new Hashtable<String, Object>()); }
public void bind(final Name name, final Object object, final Class<?> bindType) throws NamingException { bind(name, object); }
public void rebind(final Name name, final Object object, final Class<?> bindType) throws NamingException { rebind(name, object); }
binderService.getManagedObjectInjector().inject(new ImmediateManagedReferenceFactory(object)); final ServiceBuilder<?> builder = serviceTarget.addService(bindName, binderService) .addDependency(getServiceNameBase(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()); final ServiceController<?> binderServiceController = builder.install(); final StabilityMonitor monitor = new StabilityMonitor();
private void unbind(final Name name, final ServiceName bindName) throws NamingException { final ServiceController<?> controller = getServiceRegistry().getService(bindName); if (controller == null) { throw MESSAGES.cannotResolveService(bindName); } final UnbindListener listener = new UnbindListener(); controller.addListener(listener); try { // when added, the listener stops the binding service listener.await(); } catch (Exception e) { throw namingException("Failed to unbind [" + bindName + "]", e); } }
@Override public ResetContextHandle setup() throws IllegalStateException { if(namespaceContextSelector != null) { NamespaceContextSelector.pushCurrentSelector(namespaceContextSelector); } if(duServiceName != null) { WritableServiceBasedNamingStore.pushOwner(duServiceName); } return this; }
@Override public void teardown(Map<String, Object> properties) { NamespaceContextSelector.popCurrentSelector(); WritableServiceBasedNamingStore.popOwner(); }
public void bind(final Name name, final Object object) throws NamingException { final Object owner = requireOwner(); final ServiceName bindName = buildServiceName(name); bind(name, object, owner, bindName); }
public void unbind(final Name name) throws NamingException { requireOwner(); final ServiceName bindName = buildServiceName(name); final ServiceController<?> controller = getServiceRegistry().getService(bindName); if (controller == null) { throw NamingLogger.ROOT_LOGGER.cannotResolveService(bindName); } controller.setMode(ServiceController.Mode.REMOVE); final StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(controller); try { monitor.awaitStability(); } catch (Exception e) { throw namingException("Failed to unbind [" + bindName + "]", e); } finally { monitor.removeController(controller); } }
public Context createSubcontext(final Name name) throws NamingException { requireOwner(); if (isLastComponentEmpty(name)) { throw NamingLogger.ROOT_LOGGER.emptyNameNotAllowed(); } return new NamingContext(name, WritableServiceBasedNamingStore.this, new Hashtable<String, Object>()); }