@Override public ServicesConfig getServicesConfig() { return graniteContext.getServicesConfig(); }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Map<String, Object> cache = context.getSessionMap(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); String key = TideServiceInvoker.class.getName() + '.' + destinationId; return getServiceInvoker(cache, destination, key); }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Map<String, Object> cache = context.getApplicationMap(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); String key = TideServiceInvoker.class.getName() + '.' + destinationId; return getServiceInvoker(cache, destination, key); }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId); destination.addRemoveListener(this); Map<String, Object> cache = getCache(destination); String key = SimpleServiceInvoker.class.getName() + '.' + destination.getId(); if (invalidKeys.contains(key)) { cache.remove(key); invalidKeys.remove(key); } SimpleServiceInvoker service = (SimpleServiceInvoker)cache.get(key); if (service == null) { service = new SimpleServiceInvoker(destination, this); cache.put(key, service); } return service; }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Destination destination = context.getServicesConfig().findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId); destination.addRemoveListener(this); Map<String, Object> cache = getCache(destination); String key = SimpleServiceInvoker.class.getName() + '.' + destination.getId(); if (invalidKeys.contains(key)) { cache.remove(key); invalidKeys.remove(key); } SimpleServiceInvoker service = (SimpleServiceInvoker)cache.get(key); if (service == null) { service = new SimpleServiceInvoker(destination, this); cache.put(key, service); } return service; }
protected Channel getChannel() { if (channel == null) { String channelId = context.getAMFContext().getChannelId(); if (channelId != null) channel = context.getServicesConfig().findChannelById(channelId); if (channel == null) log.debug("Could not get channel for channel id: %s", channelId); } return channel; } }
private GraniteSecurity getSecurityHandler() { GraniteContext graniteContext = GraniteManager.getCurrentInstance(); if (graniteContext != null) { Message message = graniteContext.getAMFContext().getRequest(); Service service = graniteContext.getServicesConfig().findServiceByDestination(message.getDestination()); if (service != null) { synchronized (securityMap) { return securityMap.get(service.getId()); } } } return null; }
public static ServiceFactory getFactoryInstance(RemotingMessage request) throws ServiceException { GraniteContext context = GraniteContext.getCurrentInstance(); String messageType = request.getClass().getName(); String destinationId = request.getDestination(); log.debug(">> Finding factoryId for messageType: %s and destinationId: %s", messageType, destinationId); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("Destination not found: " + destinationId); String factoryId = destination.getProperties().get("factory"); log.debug(">> Found factoryId: %s", factoryId); Map<String, Object> cache = context.getApplicationMap(); String key = ServiceFactory.class.getName() + '.' + factoryId; return getServiceFactory(cache, context, factoryId, key); }
public static ServiceFactory getFactoryInstance(RemotingMessage request) throws ServiceException { GraniteContext context = GraniteContext.getCurrentInstance(); String messageType = request.getClass().getName(); String destinationId = request.getDestination(); log.debug(">> Finding factoryId for messageType: %s and destinationId: %s", messageType, destinationId); Destination destination = context.getServicesConfig().findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("Destination not found: " + destinationId); String factoryId = destination.getProperties().get("factory"); log.debug(">> Found factoryId: %s", factoryId); Map<String, Object> cache = context.getApplicationMap(); String key = ServiceFactory.class.getName() + '.' + factoryId; return getServiceFactory(cache, context, factoryId, key); }
Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById( request.getClass().getName(), destinationId
private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = context.getServicesConfig().findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }
private static ServiceFactory getServiceFactory(Map<String, Object> cache, GraniteContext context, String factoryId, String key) { lock.lock(); try { ServiceFactory factory = (ServiceFactory)cache.get(key); if (factory == null) { log.debug(">> No cached factory for: %s", factoryId); Factory config = ((ServicesConfig)context.getServicesConfig()).findFactoryById(factoryId); if (config == null) config = getDefaultFactoryConfig(); try { Class<? extends ServiceFactory> clazz = TypeUtil.forName(config.getClassName(), ServiceFactory.class); factory = clazz.newInstance(); factory.configure(config.getProperties()); } catch (Exception e) { throw new ServiceException("Could not instantiate factory: " + factoryId + " of type " + config.getClassName(), e); } cache.put(key, factory); } else log.debug(">> Found a cached factory for: %s", factoryId); log.debug("<< Returning factory: %s", factory); return factory; } finally { lock.unlock(); } }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); ServicesConfig servicesConfig = GraniteContext.getCurrentInstance().getServicesConfig(); Destination destination = servicesConfig.findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId); if (!destination.getProperties().containsKey(TideServiceInvoker.VALIDATOR_CLASS_NAME)) destination.getProperties().put(TideServiceInvoker.VALIDATOR_CLASS_NAME, "org.granite.tide.validation.BeanValidation"); @SuppressWarnings("unchecked") Bean<PersistenceConfiguration> pcBean = (Bean<PersistenceConfiguration>)manager.getBeans(PersistenceConfiguration.class).iterator().next(); PersistenceConfiguration persistenceConfiguration = (PersistenceConfiguration)manager.getReference(pcBean, PersistenceConfiguration.class, manager.createCreationalContext(pcBean)); if (destination.getProperties().containsKey(ENTITY_MANAGER_FACTORY_JNDI_NAME)) persistenceConfiguration.setEntityManagerFactoryJndiName(destination.getProperties().get(ENTITY_MANAGER_FACTORY_JNDI_NAME)); else if (destination.getProperties().containsKey(ENTITY_MANAGER_JNDI_NAME)) persistenceConfiguration.setEntityManagerJndiName(destination.getProperties().get(ENTITY_MANAGER_JNDI_NAME)); // Create an instance of the component CDIServiceInvoker invoker = new CDIServiceInvoker(destination, this); return invoker; } }
Destination destination = context.getServicesConfig().findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId);
public AMF3Serializer(OutputStream out, int capacity) { this.out = out; this.buffer = new byte[capacity]; this.position = 0; this.storedStrings = new StringIndexedCache(); this.storedObjects = new ObjectIndexedCache(); this.storedClassDescriptors = new IdentityHashMap<Class<?>, IndexedJavaClassDescriptor>(); this.writersCache = new IdentityHashMap<Class<?>, AMF3Writer>(64); GraniteContext context = GraniteContext.getCurrentInstance(); ConvertersConfig convertersConfig = (ConvertersConfig)context.getGraniteConfig(); this.converters = convertersConfig.getConverters(); this.classGetter = convertersConfig.getClassGetter(); this.xmlUtil = XMLUtilFactory.getXMLUtil(); this.externalizersConfig = (ExternalizersConfig)context.getGraniteConfig(); this.externalizeLong = (externalizersConfig.getExternalizer(Long.class.getName()) != null); this.externalizeBigInteger = (externalizersConfig.getExternalizer(BigInteger.class.getName()) != null); this.externalizeBigDecimal = (externalizersConfig.getExternalizer(BigDecimal.class.getName()) != null); String channelId = context.getAMFContext().getChannelId(); ChannelConfig channelConfig = context.getServicesConfig(); this.legacyXmlSerialization = getChannelProperty(channelId, channelConfig, "legacyXmlSerialization"); this.legacyCollectionSerialization = getChannelProperty(channelId, channelConfig, "legacyCollectionSerialization"); }
public AMF3Serializer(OutputStream out, int capacity) { this.out = out; this.buffer = new byte[capacity]; this.position = 0; this.storedStrings = new StringIndexedCache(); this.storedObjects = new ObjectIndexedCache(); this.storedClassDescriptors = new IdentityHashMap<Class<?>, IndexedJavaClassDescriptor>(); this.writersCache = new IdentityHashMap<Class<?>, AMF3Writer>(64); GraniteContext context = GraniteContext.getCurrentInstance(); ConvertersConfig convertersConfig = (ConvertersConfig)context.getGraniteConfig(); this.converters = convertersConfig.getConverters(); this.classGetter = convertersConfig.getClassGetter(); this.xmlUtil = XMLUtilFactory.getXMLUtil(); this.externalizersConfig = (ExternalizersConfig)context.getGraniteConfig(); this.externalizeLong = (externalizersConfig.getExternalizer(Long.class.getName()) != null); this.externalizeBigInteger = (externalizersConfig.getExternalizer(BigInteger.class.getName()) != null); this.externalizeBigDecimal = (externalizersConfig.getExternalizer(BigDecimal.class.getName()) != null); String channelId = context.getAMFContext().getChannelId(); ChannelConfig channelConfig = context.getServicesConfig(); this.legacyXmlSerialization = getChannelProperty(channelId, channelConfig, "legacyXmlSerialization"); this.legacyCollectionSerialization = getChannelProperty(channelId, channelConfig, "legacyCollectionSerialization"); }
public AMF3Serializer(OutputStream out, int capacity) { this.out = out; this.buffer = new byte[capacity]; this.position = 0; this.storedStrings = new StringIndexedCache(); this.storedObjects = new ObjectIndexedCache(); this.storedClassDescriptors = new IdentityHashMap<Class<?>, IndexedJavaClassDescriptor>(); this.writersCache = new IdentityHashMap<Class<?>, AMF3Writer>(64); GraniteContext context = GraniteContext.getCurrentInstance(); ConvertersConfig convertersConfig = (ConvertersConfig)context.getGraniteConfig(); this.converters = convertersConfig.getConverters(); this.classGetter = convertersConfig.getClassGetter(); this.xmlUtil = XMLUtilFactory.getXMLUtil(); this.externalizersConfig = (ExternalizersConfig)context.getGraniteConfig(); this.externalizeLong = (externalizersConfig.getExternalizer(Long.class.getName()) != null); this.externalizeBigInteger = (externalizersConfig.getExternalizer(BigInteger.class.getName()) != null); this.externalizeBigDecimal = (externalizersConfig.getExternalizer(BigDecimal.class.getName()) != null); String channelId = context.getAMFContext().getChannelId(); ChannelConfig channelConfig = context.getServicesConfig(); this.legacyXmlSerialization = getChannelProperty(channelId, channelConfig, "legacyXmlSerialization"); this.legacyCollectionSerialization = getChannelProperty(channelId, channelConfig, "legacyCollectionSerialization"); }
public ServiceAdapter getServiceAdapter(String messageType, String destinationId) throws ServiceException { GraniteContext context = GraniteContext.getCurrentInstance(); log.debug(">> Finding serviceAdapter for messageType: %s and destinationId: %s", messageType, destinationId); ServicesConfig servicesConfig = context.getServicesConfig(); Destination destination = servicesConfig.findDestinationById(messageType, destinationId); if (destination == null) { log.debug(">> No destination found: %s", destinationId); return null; } Adapter adapter = destination.getAdapter(); String key = null; if (adapter != null) { log.debug(">> Found adapterRef: %s", adapter.getId()); key = AdapterFactory.class.getName() + '@' + destination.getId() + '.' + adapter.getId(); } else key = defaultAdapterClass.getName() + '@' + destination.getId(); return getServiceAdapter(adaptersCache, context, destination, key, adapter != null ? adapter.getId() : null); }
Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById( message.getClass().getName(), message.getDestination()
final Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById( message.getMessageRefType(), message.getDestination()