@Override public ModuleURN unmarshal(String inValue) throws Exception { return new ModuleURN(inValue); }
/** * Constructs a <code>ModuleURN</code> to use to request market data. * * @param inSource a <code>String</code> value containing the name of the provider * @return */ private static ModuleURN constructMarketDataUrn(String inSource) { return new ModuleURN(String.format("metc:mdata:%s", //$NON-NLS-1$ inSource)); } /**
/** * Returns the parent URN of this URN, if this is a provider * or an instance URN, null otherwise. * * @return the parent URN if this is a provider or an instance URN. */ public ModuleURN parent() { if(mURNPieces.length > 2) { return new ModuleURN(Arrays.copyOfRange(mURNPieces, 0, mURNPieces.length - 1)); } return null; }
@Override public Module create(Object... inParameters) throws ModuleCreationException { return new EmitterModule(new ModuleURN(PROVIDER_URN, (String)inParameters[0])); }
/** * Converts a string value to Module URN value. If the supplied * string value is null or empty, the returned value is null. * * @param inURN the module URN represented as a string. * * @return the module URN value. */ private ModuleURN toModuleURN(String inURN) { return inURN == null || inURN.trim().isEmpty() ? null : new ModuleURN(inURN); }
/** * Constructs a <code>ModuleURN</code> for a <code>CEP</code> module from the given components. * * @param inSource a <code>String</code> value containing the name of a <code>CEP</code> provider * @param inNamespace a <code>String</code> value containing the namespace of a <code>CEP</code> provider query * @return a <code>ModuleURN</code> value containing the URN of the CEP module - there is no guarantee that this * URN exists or is started */ private static ModuleURN constructCepUrn(String inSource, String inNamespace) { // this should live somewhere in CEP - don't like this assert(inSource != null); assert(inNamespace != null); return new ModuleURN(String.format("metc:cep:%s:%s", //$NON-NLS-1$ inSource, inNamespace)); } /**
/** * Get the instance URN for the given market data provider name. * * @param inProviderName a <code>String</code> value * @return a <code>ModuleURN</code> value */ private ModuleURN getInstanceUrn(String inProviderName) { ModuleURN instanceUrn = instanceUrnsByProviderName.get(inProviderName); if(instanceUrn == null) { instanceUrn = new ModuleURN("metc:mdata:" + inProviderName+":single"); instanceUrnsByProviderName.put(inProviderName, instanceUrn); } return instanceUrn; } /**
/** * Generates an instance URN guaranteed to be unique with the scope of this JVM. * * @return a <code>ModuleURN</code> value */ private static final ModuleURN generateInstanceURN(String inName) { // the sanitized name is constructed to match the restrictions of the module framework for URN names // notice that this works for ASCII stuff only, which is what we want. if the incoming name is non-ASCII, // all the characters will be removed, again, according to how the module framework demands. String sanitizedName = inName.replaceAll("[^A-Z|a-z|0-9]", //$NON-NLS-1$ ""); //$NON-NLS-1$ return new ModuleURN(StrategyModuleFactory.PROVIDER_URN, String.format("strategy%s%s", //$NON-NLS-1$ sanitizedName, Integer.toHexString(counter.incrementAndGet()))); } /**
@Override public Module create(Object... inParameters) throws ModuleCreationException { if(inParameters == null || inParameters.length != 1) { throw new ModuleCreationException(Messages.PARAMETER_COUNT_ERROR); } String instanceName = String.valueOf(inParameters[0]); return new HeadwaterModule(new ModuleURN(PROVIDER_URN, instanceName), instanceName); } /**
@Override public Module create(Object... inParameters) throws ModuleCreationException { if(inParameters == null || inParameters.length != 1) { throw new ModuleCreationException(Messages.PARAMETER_COUNT_ERROR); } ISubscriber subscriber = (ISubscriber)inParameters[0]; return new PublisherModule(new ModuleURN(PROVIDER_URN, "instance"+counter.incrementAndGet()), subscriber); } /**
@Override public void setOutputDestination(String inDestination) { if(inDestination == null || inDestination.isEmpty()) { outputDestination = null; SLF4JLoggerProxy.debug(StrategyModule.class, "Setting output destination to null"); //$NON-NLS-1$ return; } outputDestination = new ModuleURN(inDestination); SLF4JLoggerProxy.debug(StrategyModule.class, "Setting output destination to {}", //$NON-NLS-1$ outputDestination); } /* (non-Javadoc)
@Override public String createModule(String providerURN, String parameters) { try { ModuleURN urn = mManager.createModuleJMX( new ModuleURN(providerURN), parameters); return urn.getValue(); } catch (ModuleException e) { throw transformFailure(e); } }
@SuppressWarnings("rawtypes") public Object convert(Class inClass, Object o) { if(ModuleURN.class.equals(inClass)) { try { if(o instanceof ModuleURN) { return o; } else if(o instanceof String) { return new ModuleURN((String)o); } else if(o != null) { return new ModuleURN(o.toString()); } } catch (IllegalArgumentException e) { throw new ConversionException(new I18NBoundMessage1P( Messages.CANNOT_CONVERT_TO_MODULE_URN, o.toString()).getText(),e); } } throw new ConversionException(new I18NBoundMessage1P( Messages.CANNOT_CONVERT_TO_MODULE_URN, o == null ? null : o.toString()).getText()); } }
@Override public List<ModuleURN> getProviders() throws ConnectionException { failIfDisconnected(); try { RpcSAClient.ProvidersResponse response = clientService.getProviders(controller, RpcSAClient.ProvidersRequest.newBuilder().setSessionId(sessionId.getValue()).build()); List<ModuleURN> providers = Lists.newArrayList(); for(RpcSAClient.ModuleURN provider : response.getProviderList()) { providers.add(new ModuleURN(provider.getValue())); } return providers; } catch (ServiceException e) { throw wrapRemoteFailure(e); } } /* (non-Javadoc)
@Override public List<ModuleURN> getInstances(ModuleURN inProviderURN) throws ConnectionException { failIfDisconnected(); try { RpcSAClient.InstancesResponse response = clientService.getInstances(controller, RpcSAClient.InstancesRequest.newBuilder().setSessionId(sessionId.getValue()) .setProvider(RpcSAClient.ModuleURN.newBuilder().setValue(inProviderURN.getValue())).build()); List<ModuleURN> instances = Lists.newArrayList(); for(RpcSAClient.ModuleURN instance : response.getInstanceList()) { instances.add(new ModuleURN(instance.getValue())); } return instances; } catch (ServiceException e) { throw wrapRemoteFailure(e); } } /* (non-Javadoc)
@Override public DeleteResponse delete(RpcController inController, DeleteRequest inRequest) throws ServiceException { serverServices.validateAndReturnSession(inRequest.getSessionId()); ModuleURN instance = new ModuleURN(inRequest.getInstance().getValue()); SLF4JLoggerProxy.debug(this, "{} received delete for {} request", DESCRIPTION, instance); RpcSAClient.DeleteResponse.Builder responseBuilder = RpcSAClient.DeleteResponse.newBuilder(); serviceAdapter.delete(instance); SLF4JLoggerProxy.debug(this, "{} returning from delete call", DESCRIPTION); return responseBuilder.build(); } /* (non-Javadoc)
@Override public StopResponse stop(RpcController inController, StopRequest inRequest) throws ServiceException { serverServices.validateAndReturnSession(inRequest.getSessionId()); ModuleURN instance = new ModuleURN(inRequest.getInstance().getValue()); SLF4JLoggerProxy.debug(this, "{} received stop for {} request", DESCRIPTION, instance); RpcSAClient.StopResponse.Builder responseBuilder = RpcSAClient.StopResponse.newBuilder(); serviceAdapter.stop(instance); SLF4JLoggerProxy.debug(this, "{} returning from stop call", DESCRIPTION); return responseBuilder.build(); } /* (non-Javadoc)
@Override public StartResponse start(RpcController inController, StartRequest inRequest) throws ServiceException { serverServices.validateAndReturnSession(inRequest.getSessionId()); ModuleURN instance = new ModuleURN(inRequest.getInstance().getValue()); SLF4JLoggerProxy.debug(this, "{} received start for {} request", DESCRIPTION, instance); RpcSAClient.StartResponse.Builder responseBuilder = RpcSAClient.StartResponse.newBuilder(); serviceAdapter.start(instance); SLF4JLoggerProxy.debug(this, "{} returning from start call", DESCRIPTION); return responseBuilder.build(); } /* (non-Javadoc)
@Override public ModuleURN createStrategy(CreateStrategyParameters inParameters) throws ConnectionException { failIfDisconnected(); try { RpcSAClient.CreateStrategyResponse response = clientService.createStrategy(controller, RpcSAClient.CreateStrategyRequest.newBuilder().setSessionId(sessionId.getValue()) .setCreateStrategyParameters(RpcSAClient.CreateStrategyParameters.newBuilder().setPayload(marshal(inParameters)).build()).build()); ModuleURN instance = new ModuleURN(response.getInstance().getValue()); return instance; } catch (ServiceException | JAXBException e) { throw wrapRemoteFailure(e); } } /* (non-Javadoc)
@Override public ModuleInfoResponse getModuleInfo(RpcController inController, ModuleInfoRequest inRequest) throws ServiceException { serverServices.validateAndReturnSession(inRequest.getSessionId()); ModuleURN instance = new ModuleURN(inRequest.getInstance().getValue()); SLF4JLoggerProxy.debug(this, "{} received getModuleInfo for {} request", DESCRIPTION, instance); ModuleInfo info = serviceAdapter.getModuleInfo(instance); RpcSAClient.ModuleInfoResponse.Builder responseBuilder = RpcSAClient.ModuleInfoResponse.newBuilder(); if(info != null) { try { responseBuilder.setInfo(RpcSAClient.ModuleInfo.newBuilder().setPayload(serverServices.marshal(info))); } catch (JAXBException e) { throw new ServiceException(e); } } RpcSAClient.ModuleInfoResponse response = responseBuilder.build(); SLF4JLoggerProxy.debug(this, "{} returning {}", DESCRIPTION, info); return response; } /* (non-Javadoc)