@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); }
public void initServices(ServicesConfig servicesConfig) { Channel channel = servicesConfig.findChannelById("graniteamf"); if (channel == null) { channel = new Channel("graniteamf", "mx.messaging.channels.AMFChannel", new EndPoint("http://{server.name}:{server.port}/{context.root}/graniteamf/amf", "flex.messaging.endpoints.AMFEndpoint"), new XMap()); servicesConfig.addChannel(channel); } List<Service> services = servicesConfig.findServicesByMessageType("flex.messaging.messages.RemotingMessage"); Service service = null; if (services == null || services.isEmpty()) { service = new Service("granite-service", "flex.messaging.services.RemotingService", "flex.messaging.messages.RemotingMessage", null, null, new HashMap<String, Destination>()); servicesConfig.addService(service); } else service = services.get(0); service.getDestinations().put(source, buildDestination()); log.info("Registered remote destination %s", source); }
@Validate public void start() { log.debug("Start Factory: " + toString()); if (servicesConfig.findFactoryById(id) == null) { servicesConfig.addFactory(this); started = true; } else { log.error("Factory \"" + id + "\" already registered"); } }
@Validate public void start() { log.debug("Start OSGiServiceSimple: " + toString()); if (servicesConfig.findServiceById(id) == null) { // Clear destinations destinations.clear(); servicesConfig.addService(this); started = true; } else { log.error("Service \"" + id + "\" already registered"); } }
Channel channel = servicesConfig.findChannelById("graniteamf"); if (channel == null) { channel = new Channel("graniteamf", "mx.messaging.channels.AMFChannel", new EndPoint("http://{server.name}:{server.port}/{context.root}/graniteamf/amf", "flex.messaging.endpoints.AMFEndpoint"), new XMap()); servicesConfig.addChannel(channel); Factory factory = servicesConfig.findFactoryById("tide-" + type + "-factory"); if (factory == null) { factory = new Factory("tide-" + type + "-factory", factoryClass.getName(), factoryProperties); servicesConfig.addFactory(factory); Service service = servicesConfig.findServiceById("granite-service"); if (service == null) { service = new Service("granite-service", "flex.messaging.services.RemotingService", servicesConfig.addService(service); servicesConfig.scan(null); servicesConfig.addFactory(factory); servicesConfig.addService(service); servicesConfig.scan(null);
@Validate public void start() { log.debug("Start OSGiChannelGranite: " + toString()); if (servicesConfig.findChannelById(id) == null) { try { Dictionary properties = new Hashtable(); properties.put("URI", endPoint.getUri()); Dictionary filters = new Hashtable(); filters.put("context", "(ID=" + context + ")"); properties.put("requires.filters", filters); servlet = servletBuilder.createComponentInstance(properties); servicesConfig.addChannel(this); started = true; } catch (Exception e) { log.error("Can't create the servlet for \"" + id + "\""); } } else { log.error("Channel \"" + id + "\" already registered"); } }
@Override public boolean getChannelProperty(String channelId, String propertyName) { if (channelId == null) return false; Channel channel = findChannelById(channelId); if (channel == null) { log.debug("Could not get channel for channel id: %s", channelId); return false; } if ("legacyXmlSerialization".equals(propertyName)) return channel.isLegacyXmlSerialization(); else if ("legacyCollectionSerialization".equals(propertyName)) return channel.isLegacyCollectionSerialization(); return false; }
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(); } }
public void load() { InputStream is = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(graniteStdConfigPath); if (graniteConfigPath != null) is = Thread.currentThread().getContextClassLoader().getResourceAsStream(graniteConfigPath); graniteConfig = new GraniteConfig(graniteStdConfigPath, is, null, null); postLoad(graniteConfig); servicesConfig = new ServicesConfig(null, null, false); } catch (Exception e) { graniteConfig = null; servicesConfig = null; throw new RuntimeException("Cannot load configuration", e); } finally { if (is != null) try { is.close(); } catch (IOException e) { } } }
public void handleScannedItem(ScannedItem item) { if ("class".equals(item.getExtension()) && item.getName().indexOf('$') == -1) { try { handleClass(item.loadAsClass()); } catch (Throwable t) { log.error(t, "Could not load class: %s", item); } } }
private void loadConfig(InputStream configIs) throws IOException, SAXException { XMap doc = new XMap(configIs); forElement(doc); }
@Validate public void start() { log.debug("Start OSGiChannelGravity: " + toString()); if (servicesConfig.findChannelById(id) == null) { try { Dictionary properties = new Hashtable(); properties.put("URI", endPoint.getUri()); Dictionary filters = new Hashtable(); filters.put("context", "(ID=" + context + ")"); properties.put("requires.filters", filters); servlet = servletBuilder.createComponentInstance(properties); servicesConfig.addChannel(this); started = true; } catch (Exception e) { log.error("Can't create the servlet for \"" + id + "\""); } } else { log.error("Channel \"" + id + "\" already registered"); } }
@Validate public void start() { log.debug("Start OSGiServiceAdapter: " + toString()); if (servicesConfig.findServiceById(id) == null) { servicesConfig.addService(this); // Clear destinations destinations.clear(); this.defaultAdapter = adapter; started = true; } else { log.error("Service \"" + id + "\" already registered"); } }
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 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(); } }
ServicesConfig servicesConfig = new ServicesConfig(is, configuration, skipScan ? false : graniteConfig.getScan());
public void handleScannedItem(ScannedItem item) { if ("class".equals(item.getExtension()) && item.getName().indexOf('$') == -1) { try { handleClass(item.loadAsClass()); } catch (Throwable t) { log.error(t, "Could not load class: %s", item); } } }
private void loadConfig(InputStream configIs) throws IOException, SAXException { XMap doc = new XMap(configIs); forElement(doc); }
@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); }
public void initServices(ServicesConfig servicesConfig) { Channel channel = servicesConfig.findChannelById("gravityamf"); if (channel == null) { channel = new Channel("gravityamf", "org.granite.gravity.channels.GravityChannel", new EndPoint("http://{server.name}:{server.port}/{context.root}/gravityamf/amf", "flex.messaging.endpoints.AMFEndpoint"), new XMap()); servicesConfig.addChannel(channel); List<Service> services = servicesConfig.findServicesByMessageType("flex.messaging.messages.AsyncMessage"); Service service = null; Adapter adapter = null; service = new Service("gravity-service", "flex.messaging.services.MessagingService", "flex.messaging.messages.AsyncMessage", adapter, adapters, new HashMap<String, Destination>()); servicesConfig.addService(service);