public Registration registerService(final String serviceType, final OpenListener openListener, final OptionMap optionMap) throws ServiceRegistrationException { if (! VALID_SERVICE_PATTERN.matcher(serviceType).matches()) { throw new IllegalArgumentException("Service type must match " + VALID_SERVICE_PATTERN); } final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(RemotingPermission.REGISTER_SERVICE); } final RegisteredServiceImpl registeredService = new RegisteredServiceImpl(openListener, optionMap); if (registeredServices.putIfAbsent(serviceType, registeredService) != null) { throw new ServiceRegistrationException("Service type '" + serviceType + "' is already registered"); } final MapRegistration<RegisteredServiceImpl> registration = new MapRegistration<RegisteredServiceImpl>(registeredServices, serviceType, registeredService) { protected void closeAction() throws IOException { try { openListener.registrationTerminated(); } finally { super.closeAction(); } } }; // automatically close the registration when the endpoint is closed final Key key = addCloseHandler(SpiUtils.closingCloseHandler(registration)); registration.addCloseHandler((closed, exception) -> key.remove()); return registration; }
public Registration registerService(final String serviceType, final OpenListener openListener, final OptionMap optionMap) throws ServiceRegistrationException { if (! VALID_SERVICE_PATTERN.matcher(serviceType).matches()) { throw new IllegalArgumentException("Service type must match " + VALID_SERVICE_PATTERN); } final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(REGISTER_SERVICE_PERM); } final RegisteredServiceImpl registeredService = new RegisteredServiceImpl(openListener, optionMap); if (registeredServices.putIfAbsent(serviceType, registeredService) != null) { throw new ServiceRegistrationException("Service type '" + serviceType + "' is already registered"); } final MapRegistration<RegisteredServiceImpl> registration = new MapRegistration<RegisteredServiceImpl>(registeredServices, serviceType, registeredService) { protected void closeAction() throws IOException { try { openListener.registrationTerminated(); } finally { super.closeAction(); } } }; // automatically close the registration when the endpoint is closed final Key key = addCloseHandler(SpiUtils.closingCloseHandler(registration)); registration.addCloseHandler(new CloseHandler<Registration>() { public void handleClose(final Registration closed, final IOException exception) { key.remove(); } }); return registration; }
public Registration registerService(final String serviceType, final OpenListener openListener, final OptionMap optionMap) throws ServiceRegistrationException { if (! VALID_SERVICE_PATTERN.matcher(serviceType).matches()) { throw new IllegalArgumentException("Service type must match " + VALID_SERVICE_PATTERN); } final SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(RemotingPermission.REGISTER_SERVICE); } final RegisteredServiceImpl registeredService = new RegisteredServiceImpl(openListener, optionMap); if (registeredServices.putIfAbsent(serviceType, registeredService) != null) { throw new ServiceRegistrationException("Service type '" + serviceType + "' is already registered"); } final MapRegistration<RegisteredServiceImpl> registration = new MapRegistration<RegisteredServiceImpl>(registeredServices, serviceType, registeredService) { protected void closeAction() throws IOException { try { openListener.registrationTerminated(); } finally { super.closeAction(); } } }; // automatically close the registration when the endpoint is closed final Key key = addCloseHandler(SpiUtils.closingCloseHandler(registration)); registration.addCloseHandler((closed, exception) -> key.remove()); return registration; }