@Override public void start ( final BundleContext context ) throws Exception { super.start ( context ); plugin = this; this.treeRoot = new WritableSet ( DisplayRealm.getRealm ( getWorkbench ().getDisplay () ) ); this.treeRootManager = new ConnectionTreeManager ( this.treeRoot ); this.connectionManager = new ConnectionManager ( context ); for ( final Map.Entry<Class<?>, IAdapterFactory> entry : this.adaperFactories.entrySet () ) { Platform.getAdapterManager ().registerAdapters ( entry.getValue (), entry.getKey () ); } }
public StorageImpl ( final File file, final BundleContext context, final DataFilePool pool, final ScheduledExecutorService queryExecutor, final ScheduledExecutorService updateExecutor, final ScheduledExecutorService eventExecutor ) throws Exception { super ( file, pool, queryExecutor, eventExecutor ); this.updateExecutor = updateExecutor; this.heartbeatJob = updateExecutor.scheduleAtFixedRate ( new Runnable () { @Override public void run () { heartbeat (); } }, 0, getHeartbeatPeriod (), TimeUnit.MILLISECONDS ); // register with OSGi final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( Constants.SERVICE_PID, this.id ); this.handle = context.registerService ( StorageHistoricalItem.class, this, properties ); }
@Override protected Entry<ComponentFactory> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters ); final String xml = cfg.getStringNonEmpty ( "configuration" ); final XMIResource xmi = new XMIResourceImpl (); final Map<?, ?> options = new HashMap<Object, Object> (); final InputSource is = new InputSource ( new StringReader ( xml ) ); xmi.load ( is, options ); final Object c = EcoreUtil.getObjectByType ( xmi.getContents (), ParserPackage.Literals.COMPONENT ); if ( ! ( c instanceof Component ) ) { throw new RuntimeException ( String.format ( "Configuration did not contain an object of type %s", Component.class.getName () ) ); } final ComponentFactoryWrapper wrapper = new ComponentFactoryWrapper ( this.executor, (Component)c ); final Dictionary<String, ?> properties = new Hashtable<> (); final ServiceRegistration<ComponentFactory> handle = context.registerService ( ComponentFactory.class, wrapper, properties ); return new Entry<ComponentFactory> ( configurationId, wrapper, handle ); }
public AbstractOsgiHiveCommon ( final BundleContext context, final Executor executor ) { this.context = context; this.executor = executor; if ( context != null ) { this.authenticationImplementation = new TrackingAuthenticationImplementation ( context ); this.authorizationManager = new TrackingAuthorizationImplementation ( context ); this.authorizationTracker = new TrackingAuthorizationTracker ( context ); this.auditLogTracker = new TrackingAuditLogImplementation ( context ); setAuthenticationImplementation ( this.authenticationImplementation ); setAuthorizationImplementation ( this.authorizationManager ); setAuditLogService ( this.auditLogTracker ); } }
protected void setUp() throws Exception { final BundleContext ctx = new MockBundleContext(); prop.setProperty("foo", "bar"); platform = new AbstractOsgiPlatform() { Properties getPlatformProperties() { return prop; } public BundleContext getBundleContext() { return ctx; } public void start() throws Exception { } public void stop() throws Exception { } }; }
private static Set<ServiceRegistration<?>> registerToSR(final AutoCloseable instance, final BundleContext bundleContext, final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) { Set<ServiceRegistration<?>> serviceRegistrations = new HashSet<>(); for (Entry<ServiceInterfaceAnnotation, String /* service ref name */> entry : serviceNamesToAnnotations .entrySet()) { ServiceInterfaceAnnotation annotation = entry.getKey(); Class<?> requiredInterface = annotation.osgiRegistrationType(); if (!annotation.registerToOsgi()) { LOG.debug("registerToOsgi for service interface {} is false - not registering", requiredInterface); continue; } Preconditions.checkState(requiredInterface.isInstance(instance), instance.getClass().getName() + " instance should implement " + requiredInterface.getName()); Dictionary<String, String> propertiesForOsgi = createProps(entry.getValue()); ServiceRegistration<?> serviceRegistration = bundleContext.registerService(requiredInterface.getName(), instance, propertiesForOsgi); serviceRegistrations.add(serviceRegistration); } return serviceRegistrations; }
@Activate void activate(BundleContext context) { this.context = context; if (doReplaceSslKeysAndReboot()) { return; } Runnable server = () -> { try { startServer(); } catch (Exception e) { log.error("startServer failed", e); } }; this.thread = new Thread(server, "Start-Server"); this.thread.start(); }
/** * Returns a reference to the <em>best matching</em> service for the given classes and OSGi filter. * * @param bundleContext OSGi bundle context * @param classes array of fully qualified class names * @param filter valid OSGi filter (can be <code>null</code>) * @return reference to the <em>best matching</em> service */ public static ServiceReference getServiceReference(BundleContext bundleContext, String[] classes, String filter) { // use #getServiceReference(BundleContext, String, String) method to // speed the service lookup process by // giving one class as a hint to the OSGi implementation String clazz = (ObjectUtils.isEmpty(classes) ? null : classes[0]); return getServiceReference(bundleContext, clazz, OsgiFilterUtils.unifyFilter(classes, filter)); }
public LocalMonitorQueryListener ( final BundleContext context, final String monitorQueryId, final ProxyMonitorQuery proxyMonitorQuery, final Lock lock ) throws InvalidSyntaxException { super ( proxyMonitorQuery, lock, monitorQueryId ); logger.info ( "Creating new listener - query: {}", monitorQueryId ); this.tracker = new SingleServiceTracker<MonitorQuery> ( context, FilterUtil.createClassAndPidFilter ( MonitorQuery.class, monitorQueryId ), this.queryListener ); this.tracker.open (); }
@Override public BundleContext getModuleFactoryBundleContext(final String factoryName) { Map.Entry<ModuleFactory, BundleContext> factoryBundleContextEntry = this.currentlyRegisteredFactories .get(factoryName); if (factoryBundleContextEntry == null || factoryBundleContextEntry.getValue() == null) { throw new NullPointerException("Bundle context of " + factoryName + " ModuleFactory not found."); } return factoryBundleContextEntry.getValue(); }
@Activate private void start(BundleContext ctx) { this.ctx = ctx; this.statusViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_ALERTS, AlertView.class, this.alertViewFactory)); this.statusViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_APPLIANCE_INSTANCES, ApplianceInstanceView.class, this.applianceInstanceViewFactory)); this.statusViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_JOBS, JobView.class, this.jobViewFactory)); this.setupViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_VIRTUALIZATION_CONNECTORS, VirtualizationConnectorView.class, this.virtualizationConnectorViewFactory)); this.setupViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_SECURITY_MANAGER_CONNECTORS, ManagerConnectorView.class, this.managerConnectorViewFactory)); this.setupViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_SECURITY_FUNCTION_CATALOG, ApplianceView.class, this.applicanceViewFactory)); this.setupViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_DISTRIBUTED_APPLIANCES, DistributedApplianceView.class, this.distributedApplicanceViewFactory)); this.manageViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_USERS, UserView.class, this.userViewFactory)); this.manageViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_ALARMS, AlarmView.class, this.alarmViewFactory)); this.manageViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_PLUGIN, PluginView.class, this.pluginViewFactory)); this.manageViews.add(new OSCViewProvider<>(VIEW_FRAGMENT_SERVER, MaintenanceView.class, this.maintenanceViewFactory)); }
@Override public void stop ( final BundleContext context ) throws Exception { this.handle.unregister (); this.factory.dispose (); this.executor.shutdown (); }
public ConfigurationFactoryImpl () { final ReadWriteLock lock = new ReentrantReadWriteLock (); this.readLock = lock.readLock (); this.writeLock = lock.writeLock (); final BundleContext context = FrameworkUtil.getBundle ( DataContext.class ).getBundleContext (); this.executor = new ScheduledExportedExecutorService ( "org.eclipse.scada.da.server.exporter.rest", 1 ); this.hiveSource = new ServiceListenerHiveSource ( context, this.executor ); this.hiveSource.open (); }
@Override public void stop ( final BundleContext context ) throws Exception { this.dataSourceTracker.close (); this.masterHandle.unregister (); this.masterFactory.dispose (); this.masterFactory = null; }
@Override protected Entry<BufferedDataSource> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { logger.debug ( "Creating new change counter source: {}", configurationId ); final BufferedDataSourceImpl source = new BufferedDataSourceImpl ( this.context, this.executor, this.poolTracker, this.dataNodeTracker, configurationId, objectPool ); source.update ( parameters ); return new Entry<BufferedDataSource> ( configurationId, source ); }
public void start ( final BundleContext context ) throws Exception { this.executor = Executors.newSingleThreadScheduledExecutor ( new ThreadFactoryImplementation ( Activator.class.getName () ) ); Dictionary<String, String> properties; // register sine factory this.factory1 = new SineDataSourceFactory ( context, this.executor ); properties = new Hashtable<String, String> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, "datasource.test.sine" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Testing Factory - Sine" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory1, properties ); // register toggle factory this.factory2 = new ToggleDataSourceFactory ( context, this.executor ); properties = new Hashtable<String, String> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, "datasource.test.toggle" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Testing Factory - Toggle" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory2, properties ); // register sawtooth factory this.factory3 = new SawtoothDataSourceFactory ( context, this.executor ); properties = new Hashtable<String, String> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, "datasource.test.sawtooth" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Testing Factory - Sawtooth" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory3, properties ); // register random long factory this.factory4 = new RandomLongDataSourceFactory ( context, this.executor ); properties = new Hashtable<String, String> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, "datasource.test.randomlong" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Testing Factory - Random Long" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory4, properties ); // register quality factory this.factory5 = new QualityDataSourceFactory ( context, this.executor ); properties = new Hashtable<String, String> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, "datasource.test.quality" ); properties.put ( Constants.SERVICE_DESCRIPTION, "Testing Factory - Quality" ); context.registerService ( ConfigurationFactory.class.getName (), this.factory5, properties ); }
@Override public void start ( final BundleContext bundleContext ) throws Exception { Activator.context = bundleContext; this.pullManager = new PullManager (); final Dictionary<String, Object> properties = new Hashtable<String, Object> (); properties.put ( ConfigurationAdministrator.FACTORY_ID, PullManager.FACTORY_ID ); properties.put ( Constants.SERVICE_DESCRIPTION, "An AE pull manager configuration" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); this.handle = bundleContext.registerService ( ConfigurationFactory.class, this.pullManager, properties ); }
@Override public SchemaServiceImplSingletonModule instantiateModule(String instanceName, DependencyResolver dependencyResolver, SchemaServiceImplSingletonModule oldModule, AutoCloseable oldInstance, BundleContext bundleContext) { checkArgument(SINGLETON_NAME.equals(instanceName),"Illegal instance name '" + instanceName + "', only allowed name is " + SINGLETON_NAME); SchemaServiceImplSingletonModule module = super.instantiateModule(instanceName, dependencyResolver, oldModule, oldInstance, bundleContext); // FIXME bundle context should not be passed around module.setBundleContext(bundleContext); return module; }
@Activate void activate(BundleContext context) { List<PluginListener> earlyArrivers; synchronized (this.pluginListeners) { this.context = context; this.listenersActive = true; earlyArrivers = this.pluginListeners.entrySet().stream().filter(e -> e.getValue().isEmpty()) .map(Entry::getKey).collect(Collectors.toList()); } earlyArrivers.stream().forEach(pl -> { // Always create trackers without holding any monitors or locks // to avoid potential deadlock List<PluginTracker<?>> trackers = createTrackers(pl); synchronized (this.pluginListeners) { if (this.listenersActive) { // We should only add the trackers if the plugin is still // in the map with an empty collection List<PluginTracker<?>> old = this.pluginListeners.get(pl); if (old != null && old.isEmpty()) { this.pluginListeners.put(pl, trackers); trackers = Collections.emptyList(); } } } // If our trackers weren't added then close them trackers.forEach(PluginTracker::close); }); }
/** * {@inheritDoc} */ @Override public void start( BundleContext bundleContext ) throws Exception { LdapApiServiceTracker ldapApiServiceTracker = new LdapApiServiceTracker( bundleContext ); serviceTracker = new ServiceTracker<>( bundleContext, LdapApiService.class, ldapApiServiceTracker ); serviceTracker.open(); }
/** * Returns the OSGi platform version (using the manifest entries from the system bundle). The version can be empty. * * @param bundleContext bundle context to inspect * @return not-null system bundle version */ public static String getVersion(BundleContext bundleContext) { if (bundleContext == null) return ""; // get system bundle Bundle sysBundle = bundleContext.getBundle(0); // force string conversion instead of casting just to be safe return "" + sysBundle.getHeaders().get(Constants.BUNDLE_VERSION); }
@Override public void start ( final BundleContext context ) throws Exception { this.executor = new ExportedExecutorService ( "org.eclipse.scada.da.server.component", 1, 1, 1, TimeUnit.MINUTES ); //$NON-NLS-1$ this.hive = new Hive ( context, this.executor ); this.hive.start (); final Dictionary<String, Object> properties = new Hashtable<> (); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( "hive.id", this.hive.getHiveId () ); //$NON-NLS-1$ this.handle = context.registerService ( org.eclipse.scada.da.core.server.Hive.class, this.hive, properties ); }
public AbstractConnectionDevice ( final BundleContext context, final String id, final NioProcessor processor, final ScheduledExecutorService executor, final String itemPrefix ) { this.id = id; this.processor = processor; this.context = context; this.itemPrefix = itemPrefix; this.executor = executor; this.itemFactory = new DataItemFactory ( context, executor, getItemId ( null ) ); this.stateItem = this.itemFactory.createInput ( "state", Collections.<String, Variant> emptyMap () ); this.connectionItem = this.itemFactory.createInput ( "connection", Collections.<String, Variant> emptyMap () ); }
@Override protected Entry<AbstractMasterHandlerImpl> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { final AbstractMasterHandlerImpl handler = new ScaleHandlerImpl ( configurationId, this.poolTracker, this.priority, this.caTracker ); handler.update ( userInformation, parameters ); return new Entry<AbstractMasterHandlerImpl> ( configurationId, handler ); }
private Class<?> findBundle ( final String symbolicName, final String clazzName ) { logger.debug ( "Find bundle with class - symbolicName: {}, className: {}", symbolicName, clazzName ); final BundleContext context = FrameworkUtil.getBundle ( DefaultExecutableFactory.class ).getBundleContext (); for ( final Bundle bundle : context.getBundles () ) { if ( !symbolicName.equals ( bundle.getSymbolicName () ) ) { continue; } logger.debug ( "Checking bundle: {}", bundle.getSymbolicName () ); Class<?> clazz; try { clazz = bundle.loadClass ( clazzName ); } catch ( final ClassNotFoundException e ) { logger.debug ( "Class could not be loaded", e ); // we continue, since we might have multiple versions continue; } logger.debug ( "Success" ); return clazz; } return null; }
@Override public void stop ( final BundleContext context ) throws Exception { this.monitorServicePoolHandler.unregister (); this.monitorServicePool.dispose (); this.processor.close (); this.service.stop (); this.executor.shutdown (); }
@Override public void start ( final BundleContext context ) throws Exception { Activator.context = context; this.executor = ScheduledExportedExecutorService.newSingleThreadExportedScheduledExecutor ( context.getBundle ().getSymbolicName () ); this.factory = new ChangeCounterDataSourceFactory ( context, this.executor ); final Dictionary<String, String> properties = new Hashtable<String, String> (); properties.put ( Constants.SERVICE_DESCRIPTION, "A counter of changes on an item over a defined timeframe" ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, context.getBundle ().getSymbolicName () ); context.registerService ( ConfigurationFactory.class.getName (), this.factory, properties ); }
public ModbusSlave ( final String id, final BundleContext context, final MasterFactory masterFactory, final Executor executor, final AtomicInteger transactionId ) { this.id = id; this.executor = executor; this.context = context; this.masterFactory = masterFactory; this.transactionId = transactionId; synchronized ( this ) { // this will send all masters, but we currently have a masterId of null, so no match this.masterFactory.addMasterListener ( this ); } }
public void stop(BundleContext context) throws Exception { plugin = null; if (viewpoints != null) { for (final Viewpoint viewpoint: viewpoints) { ViewpointRegistry.getInstance().disposeFromPlugin(viewpoint); } viewpoints.clear(); viewpoints = null; } super.stop(context); }
@Override public void start ( final BundleContext bundleContext ) throws Exception { Activator.context = bundleContext; this.pool = new DataFilePool ( Integer.getInteger ( "org.eclipse.scada.hd.server.storage.master.hds.instanceCountTarget", 10 ) ); //$NON-NLS-1$ this.manager = new StorageManager ( bundleContext, this.pool ); registerConsole (); }
@Override public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, final BundleContext bundleContext) { try { return constructModule(instanceName, dependencyResolver, null); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }
protected void postProcessBundleContext(BundleContext context) throws Exception { // hook in properties loading // reset the settings (useful when running multiple tests) jarSettings = null; // load settings jarSettings = getSettings(); // Somehow the JarCreator needs to get this jarCreator.setRootPath(getRootPath()); super.postProcessBundleContext(context); }
@Override public void stop ( final BundleContext bundleContext ) throws Exception { this.factory.dispose (); this.executor.shutdown (); this.factory = null; this.executor = null; }
@Override public void start ( final BundleContext context ) throws Exception { super.start ( context ); this.sessionManager = new SessionManagerImpl ( SWTObservables.getRealm ( getWorkbench ().getDisplay () ) ); plugin = this; }
@Override public void stop(BundleContext context) throws Exception { injectors.clear(); INSTANCE = null; super.stop(context); }
@Override public void start ( final BundleContext bundleContext ) throws Exception { Activator.context = bundleContext; this.executor = ExportedExecutorService.newSingleThreadExportedExecutor ( bundleContext.getBundle ().getSymbolicName () ); this.objectPool = new ObjectPoolImpl<DataItem> (); this.factory = new ScriptComponentFactory ( this.executor, this.objectPool, bundleContext ); final Dictionary<String, Object> properties = new Hashtable<String, Object> ( 2 ); properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" ); properties.put ( ConfigurationAdministrator.FACTORY_ID, bundleContext.getBundle ().getSymbolicName () ); this.handle = bundleContext.registerService ( ConfigurationFactory.class, this.factory, properties ); // register late in order to reduce events this.poolHandle = ObjectPoolHelper.registerObjectPool ( bundleContext, this.objectPool, DataItem.class ); }
@Override public void start(BundleContext context) throws Exception { bctx = context; logTracker = new ServiceTracker<>(context, ExtendedLogService.class, null); logTracker.open(); }
public void stop ( final BundleContext context ) throws Exception { plugin = null; super.stop ( context ); }
public Hive ( final String uri, final BundleContext bundleContext ) throws IOException { this ( parse ( URI.createURI ( uri ) ), bundleContext ); }
public ListenerTracker ( final BundleContext context ) { this.executor = ExportedExecutorService.newSingleThreadExportedExecutor ( "org.eclipse.scada.ca.common.ListenerTracker" ); this.listenerTracker = new ServiceTracker<ConfigurationAdministratorListener, ConfigurationAdministratorListener> ( context, ConfigurationAdministratorListener.class, null ); }