/** * Retrieve global instance of a class via OSGI registry, if * there are many only the first is returned. * * @param clazz The target class * @param bundle The caller */ public static Object getGlobalInstance(Class<?> clazz, Object bundle) { return getGlobalInstance(clazz, bundle, null); }
/** * Retrieve instance of a class via OSGI registry, if there * are many only the first is returned. * * @param clazz The target class * @param containerName The container name * @param bundle The caller */ public static Object getInstance(Class<?> clazz, String containerName, Object bundle) { // Back-end convention: Container id in lower case. Let's enforce it here return getInstance(clazz, containerName.toLowerCase(), bundle, null); }
protected <E> void register(Class<E> clazz) { ServiceRegistration reg = ServiceHelper.registerGlobalServiceWReg(clazz, this, null); if (reg != null) this.m_reg.add(reg); assert ServiceHelper.getGlobalInstance(clazz, this) != this; }
private IAnalyticsManager getAnalyticsService(String containerName) { IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(IContainerManager.class, this); if (containerManager == null) throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString()); boolean found = false; List<String> containerNames = containerManager.getContainerNames(); for (String cName : containerNames) if (cName.trim().equalsIgnoreCase(containerName.trim())) found = true; if (found == false) throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString()); IAnalyticsManager analyticsManager = (IAnalyticsManager) ServiceHelper.getInstance(IAnalyticsManager.class, containerName, this); if (analyticsManager == null) throw new ServiceUnavailableException("Analytics " + RestMessages.SERVICEUNAVAILABLE.toString()); return analyticsManager; }
@RequestMapping(value = "web.json") @ResponseBody public Map<String, Map<String, Object>> bundles(HttpServletRequest request) { Object[] instances = ServiceHelper.getGlobalInstances( IDaylightWeb.class, this, null); Map<String, Map<String, Object>> bundles = new HashMap<String, Map<String, Object>>(); Map<String, Object> entry; IDaylightWeb bundle; String username = request.getUserPrincipal().getName(); IUserManager userManger = (IUserManager) ServiceHelper .getGlobalInstance(IUserManager.class, this); for (Object instance : instances) { bundle = (IDaylightWeb) instance; if (userManger != null && bundle.isAuthorized(userManger.getUserLevel(username))) { entry = new HashMap<String, Object>(); entry.put("name", bundle.getWebName()); entry.put("order", bundle.getWebOrder()); bundles.put(bundle.getWebId(), entry); } } return bundles; }
/** * Retrieve global instance of a class via OSGI registry, if * there are many only the first is returned. On this version an LDAP * type of filter is applied * * @param clazz The target class * @param bundle The caller * @param serviceFilter LDAP filter to be applied in the search */ public static Object getGlobalInstance(Class<?> clazz, Object bundle, String serviceFilter) { Object[] instances = getGlobalInstances(clazz, bundle, serviceFilter); if (instances != null) { return instances[0]; } return null; }
public void start() { final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("osgi.command.scope", "odpcontroller"); props.put("osgi.command.function", new String[] { "showNodes", "showNodeConnectors" }); this.sr = ServiceHelper.registerGlobalServiceWReg(SwitchManagerCLI.class, this, props); }
public Troubleshoot() { ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null); }
private IForwardingRulesManager getForwardingRulesManagerService(String containerName) { IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance( IContainerManager.class, this); if (containerManager == null) { throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString()); } boolean found = false; List<String> containerNames = containerManager.getContainerNames(); for (String cName : containerNames) { if (cName.trim().equalsIgnoreCase(containerName.trim())) { found = true; } } if (found == false) { throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString()); } IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance( IForwardingRulesManager.class, containerName, this); if (frm == null) { throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString()); } return frm; }
Object[] instances = ServiceHelper.getGlobalInstances(INeutronFirewallPolicyAware.class, this, null); if (instances != null) { if (instances.length > 0) {
public void start() { final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("osgi.command.scope", "odpcontroller"); props.put("osgi.command.function", new String[] { "getContainerAdvancedCacheInfo" }); this.sr = ServiceHelper.registerGlobalServiceWReg(ClusterManagerCLI.class, this, props); }
public Flows() { ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null); gson = new Gson(); }
private <E> E getService(Class<E> clazz) { E service = (E)ServiceHelper.getGlobalInstance(clazz, this); if (service == null) { service = (E)ServiceHelper.getGlobalInstance(AltoService.class, this); } return service; }
private IfIptoHost getIfIpToHostService(String containerName) { IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance( IContainerManager.class, this); if (containerManager == null) { throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString()); } boolean found = false; List<String> containerNames = containerManager.getContainerNames(); for (String cName : containerNames) { if (cName.trim().equalsIgnoreCase(containerName.trim())) { found = true; break; } } if (!found) { throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString()); } IfIptoHost hostTracker = (IfIptoHost) ServiceHelper.getInstance(IfIptoHost.class, containerName, this); if (hostTracker == null) { throw new ServiceUnavailableException("Host Tracker " + RestMessages.SERVICEUNAVAILABLE.toString()); } return hostTracker; }
public static String getNodeDesc(Node node, String containerName, Object bundle) { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, bundle); if (switchManager == null) { return null; } return getNodeDesc(node, switchManager); }
Object[] instances = ServiceHelper.getGlobalInstances(INeutronLoadBalancerListenerAware.class, this, null); if (instances != null) { if (instances.length > 0) {
public void start() { final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("osgi.command.scope", "odpcontroller"); props.put("osgi.command.function", new String[] { "showRequestedGroupFlows", "showInstalledGroupFlows", "showRequestedNodeFlows", "showInstalledNodeFlows" }); this.sr = ServiceHelper.registerGlobalServiceWReg(ForwardingRulesManagerCLI.class, this, props); }
/** * Register a Service in the OSGi service registry * * @param clazz The target class * @param containerName The container name * @param instance of the object exporting the service, be careful * the object must implement/extend clazz else the registration * will fail unless a ServiceFactory is passed as parameter * @param properties The properties to be attached to the service * registration * @return true if registration happened, false otherwise */ public static boolean registerService(Class<?> clazz, String containerName, Object instance, Dictionary<String, Object> properties) { if (properties == null) { properties = (Dictionary<String, Object>) new Hashtable<String, Object>(); } properties.put("containerName", containerName); return registerGlobalService(clazz, instance, properties); }
public OpenDoveGC() { openDoveBidirectionalInterfaces = (OpenDoveBidirectionalInterfaces) ServiceHelper.getGlobalInstance( OpenDoveBidirectionalInterfaces.class, this); openDoveSBInterfaces = (OpenDoveSBInterfaces) ServiceHelper.getGlobalInstance( OpenDoveSBInterfaces.class, this); }
private ISwitchManager getIfSwitchManagerService(String containerName) { IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance( IContainerManager.class, this); if (containerManager == null) { throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString()); } boolean found = false; List<String> containerNames = containerManager.getContainerNames(); for (String cName : containerNames) { if (cName.trim().equalsIgnoreCase(containerName.trim())) { found = true; break; } } if (found == false) { throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString()); } ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString()); } return switchManager; }