/** * Create the service container. * @return The service conainer. */ public IServiceContainer createMyServiceContainer(Map args) { IServiceContainer ret = microagent.createServiceContainer(args); if(ret==null) ret = super.createServiceContainer(); return ret; }
/** * Add component fetcher to service init. */ protected IFuture<Void> initService(ProvidedServiceInfo info, IModelInfo model, IResultCommand<Object, Class<?>> componentfetcher) { return super.initService(info, model, componentfetcher!=null ? componentfetcher : getComponentFetcher()); }
/** * Can be called concurrently (also during executeAction()). * * Get the external access for this component. * The specific external access interface is kernel specific * and has to be casted to its corresponding incarnation. * @param listener External access is delivered via result listener. */ public IExternalAccess getExternalAccess() { if(access==null) { synchronized(this) { if(access==null) { access = createExternalAccess(); } } } return access; }
/** * Check if threa is allowed. * * There is the problem that a component is already terminated and calls come back later. * In that case we allow the listeners to be called on the wrong thread. */ public void checkAllowedThread() { assert !getComponentAdapter().isExternalThread() || IComponentDescription.STATE_TERMINATED.equals(getComponentDescription().getState()); }
/** * Create the service container. * @return The service conainer. */ public IServiceContainer createServiceContainer() { assert container==null; return new ComponentServiceContainer(adapter, getComponentAdapter().getDescription().getType(), getInternalAccess(), isRealtime()); }
final SubscriptionIntermediateFuture<IMonitoringEvent> ret = (SubscriptionIntermediateFuture<IMonitoringEvent>)SFuture.getNoTimeoutFuture(SubscriptionIntermediateFuture.class, getInternalAccess()); MonitoringEvent subscribed = new MonitoringEvent(getComponentIdentifier(), getComponentDescription().getCreationTime(), IMonitoringEvent.TYPE_SUBSCRIPTION_START, System.currentTimeMillis(), PublishEventLevel.COARSE); boolean post = false; addSubscription(ret, filter, emitlevel); List<IMonitoringEvent> evs = getCurrentStateEvents(); if(evs!=null && evs.size()>0)
/** * Overridden to abort remaining steps on cleanup. */ public IFuture<Void> terminateServiceContainer() { final Future<Void> ret = new Future<Void>(); super.terminateServiceContainer() .addResultListener(new DelegationResultListener<Void>(ret) { public void customResultAvailable(Void result) { nosteps = true; ComponentTerminatedException ex = new ComponentTerminatedException(getComponentAdapter().getComponentIdentifier()); while(steps!=null && !steps.isEmpty()) { Object[] step = (Object[])steps.remove(0); Future<Void> future = (Future<Void>)step[1]; future.setException(ex); } ret.setResult(null); } }); return ret; }
/** * Add a property value. * @param name The name. * @param val The value. */ public void addProperty(String name, Object val) { assert !getComponentAdapter().isExternalThread(); if(properties==null) properties = new HashMap<String, Object>(); properties.put(name, val); }
/** * Get the monitoring event emit level. */ public PublishEventLevel getPublishEmitLevelMonitoring() { return getComponentDescription().getMonitoring()!=null? getComponentDescription().getMonitoring(): PublishEventLevel.OFF; // return emitlevelmon; }
/** * Get the value fetcher. */ public IValueFetcher getFetcher() { assert !getComponentAdapter().isExternalThread(); if(fetcher==null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(super.getFetcher()); if(microagent instanceof IPojoMicroAgent) { fetcher.setValue("$pojoagent", ((IPojoMicroAgent)microagent).getPojoAgent()); } this.fetcher = fetcher; } return fetcher; }
/** * Get a space of the application. * @param name The name of the space. * @return The space. */ public IExtensionInstance[] getExtensions() { // Hack!!! When init fails , terminateExtensions() can not be called on component thread // as component already terminated. assert !getComponentAdapter().isExternalThread() || IComponentDescription.STATE_TERMINATED.equals(getComponentDescription().getState()); return extensions==null? new IExtensionInstance[0]: (IExtensionInstance[])extensions.values().toArray(new IExtensionInstance[extensions.size()]); }
/** * Called from cleanupComponent. */ public IFuture<Void> terminateServiceContainer() { final Future<Void> ret = new Future<Void>(); IResultListener<Void> reslis = new IResultListener<Void>() { public void resultAvailable(Void result) { nosteps = true; exitState(); ret.setResult(result); } public void exceptionOccurred(final Exception exception) { nosteps = true; exitState(); ret.setException(exception); } }; // If platform, do not schedule listener on component as execution service already terminated after terminate service container. if(getComponentIdentifier().getParent()!=null) reslis = createResultListener(reslis); super.terminateServiceContainer().addResultListener(reslis); return ret; }
/** * Get a space of the application. * @param name The name of the space. * @return The space. */ public IExtensionInstance getExtension(final String name) { assert !getComponentAdapter().isExternalThread(); return extensions==null? null: (IExtensionInstance)extensions.get(name); }
/** * Create a new context. */ public AbstractInterpreter(final IComponentDescription desc, final IModelInfo model, final String config, final IComponentAdapterFactory factory, final IExternalAccess parent, final RequiredServiceBinding[] bindings, boolean copy, boolean realtime, IIntermediateResultListener<Tuple2<String, Object>> resultlistener, final Future<Void> inited) { this.config = config!=null? config: model.getConfigurationNames().length>0? model.getConfigurationNames()[0]: null; this.model = model; this.parent = parent; this.bindings = bindings; this.copy = copy; this.realtime = realtime; this.emitlevelsub = PublishEventLevel.OFF; // this.emitlevelmon = desc.getMonitoring(); this.resultlistener = resultlistener; if(factory != null) this.adapter = factory.createComponentAdapter(desc, model, this, parent); this.container = createServiceContainer(); // this.arguments = arguments!=null? new HashMap(arguments): null; // clone arguments // System.out.println("hhh: "+desc.getName()+" "+desc.getCause()); }
ret = super.initService(info, model, componentfetcher);
/** * Add an extension. * @param name The argument name. * @param value The extension. */ public void addExtension(String name, IExtensionInstance value) { assert !getComponentAdapter().isExternalThread(); if(extensions==null) { extensions = new HashMap<String, IExtensionInstance>(); } extensions.put(name, value); }
/** * Add a default value for a result (if not already present). * Called once for each result during init. * @param name The result name. * @param value The result value. */ public void addDefaultResult(String name, Object value) { assert !getComponentAdapter().isExternalThread(); // System.out.println("add def res: "+name+" "+value); if(results==null) { results = new HashMap<String, Object>(); } results.put(name, value); }
/** * Get the value fetcher. */ public IValueFetcher getFetcher() { assert !getComponentAdapter().isExternalThread(); if(fetcher==null) { fetcher = new InterpreterFetcher(this); } return fetcher; }
/** * Set a result value. * @param name The result name. * @param value The result value. */ public void setResultValue(String name, Object value) { assert !getComponentAdapter().isExternalThread(); // todo: store results only within listener?! if(results==null) results = new HashMap<String, Object>(); results.put(name, value); if(resultlistener!=null) { resultlistener.intermediateResultAvailable(new Tuple2<String, Object>(name, value)); } }