/** * Create a result listener which is executed as an component step. * @param The original listener to be called. * @return The listener. */ public <T> IIntermediateResultListener<T> createResultListener(IIntermediateResultListener<T> listener) { return new IntermediateComponentResultListener<T>(listener, getComponentAdapter()); }
/** * Get the logger. * @return The logger. */ public Logger getLogger() { return getComponentAdapter().getLogger(); }
/** * Create a result listener which is executed as an component step. * @param The original listener to be called. * @return The listener. */ public <T> IResultListener<T> createResultListener(IResultListener<T> listener) { return new ComponentResultListener<T>(listener, getComponentAdapter()); }
/** * Get the component description. * @return The component description. */ public IComponentDescription getComponentDescription() { return getComponentAdapter().getDescription(); }
/** * Test if current thread is the component thread. * @return True if the current thread is the component thread. */ public boolean isComponentThread() { return !getComponentAdapter().isExternalThread(); }
/** * Get the component identifier. */ public IComponentIdentifier getComponentIdentifier() { return getComponentAdapter().getComponentIdentifier(); }
/** * Get the parent. * return The parent. */ public INFPropertyProvider getParent() { return getComponentAdapter().getParent(); } }
/** * Get the local type name of this component as defined in the parent. * @return The type of this component type. */ public String getLocalType() { return getComponentAdapter().getDescription().getLocalType(); }
/** * Get the name. */ // todo: remove. public String getName() { return getComponentAdapter().getComponentIdentifier().getLocalName(); }
/** * Get a string representation of the context. */ public String toString() { StringBuffer ret = new StringBuffer(); ret.append(SReflect.getInnerClassName(getClass())); ret.append("(name="); ret.append(getComponentAdapter().getComponentIdentifier().getLocalName()); // ret.append(", parent="); // ret.append(getParentContext()); // IComponentIdentifier[] aids = getComponents(); // if(aids!=null) // { // ret.append(", components="); // ret.append(SUtil.arrayToString(aids)); // } // IContext[] subcs = getSubContexts(); // if(subcs!=null) // { // ret.append(", subcontexts="); // ret.append(SUtil.arrayToString(subcs)); // } ret.append(")"); return ret.toString(); }
/** * Check if correct thread access. */ protected void checkThread() { if(DEBUG) { // Hack! if(((ExternalAccess)rsms.getComponent()).getInterpreter().getComponentAdapter().isExternalThread()) { System.out.println("wrong thread: "+Thread.currentThread()); Thread.dumpStack(); } } }
/** * Create an external access. */ public ExternalAccess(StatelessAbstractInterpreter interpreter) { this.interpreter = interpreter; this.adapter = interpreter.getComponentAdapter(); this.tostring = interpreter.getComponentIdentifier().getLocalName(); this.provider = interpreter.getServiceContainer(); }
/** * Start the services. */ public IFuture startServiceContainer() { assert !getComponentAdapter().isExternalThread(); return getServiceContainer().start(); }
public void customResultAvailable(IComponentManagementService cms) { cms.destroyComponent(getComponentAdapter().getComponentIdentifier()) .addResultListener(new DelegationResultListener<Map<String, Object>>(ret)); } });
/** * Get a raw reference to a provided service implementation. */ public Object getRawService(String name) { assert !getComponentAdapter().isExternalThread(); return convertRawService(getServiceContainer().getProvidedService(name)); }
/** * Get a raw reference to a provided service implementation. */ public Object getRawService(Class type) { assert !getComponentAdapter().isExternalThread(); IService[] sers = getServiceContainer().getProvidedServices(type); return convertRawService(sers[0]); }
/** * Get the number of components to start. * @return The number. */ public int getNumber(ComponentInstanceInfo component, IModelInfo model) { assert !getComponentAdapter().isExternalThread(); Object ret = component.getNumber()!=null? SJavaParser.evaluateExpression(component.getNumber(), model.getAllImports(), getFetcher(), getClassLoader()): null; return ret instanceof Integer? ((Integer)ret).intValue(): 1; }
/** * Terminate all extensions. */ public IFuture<Void> terminateExtensions() { // 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()); Future<Void> ret = new Future<Void>(); IExtensionInstance[] exts = getExtensions(); CounterResultListener<Void> lis = new CounterResultListener<Void>(exts.length, false, new DelegationResultListener<Void>(ret)); for(int i=0; i<exts.length; i++) { exts[i].terminate().addResultListener(lis); } return ret; }
/** * Get the name of components to start. * @return The name. */ public String getName(ComponentInstanceInfo component, IModelInfo model, int cnt) { assert !getComponentAdapter().isExternalThread(); String ret = component.getName(); if(ret!=null) { SimpleValueFetcher fetcher = new SimpleValueFetcher(getFetcher()); fetcher.setValue("$n", Integer.valueOf(cnt)); try { ret = (String)SJavaParser.evaluateExpression(component.getName(), model.getAllImports(), fetcher, getClassLoader()); if(ret==null) ret = component.getName(); } catch(RuntimeException e) { } } return ret; }
/** * Create a service proxy for registering a provided service. */ public IInternalService createInternalService(Object service, Class<?> type) { // boolean moni = getComponentDescription().getMonitoring()!=null? getComponentDescription().getMonitoring().booleanValue(): false; PublishEventLevel elm = getComponentDescription().getMonitoring()!=null? getComponentDescription().getMonitoring(): null; // todo: remove this? currently the level cannot be turned on due to missing interceptor boolean moni = elm!=null && !PublishEventLevel.OFF.equals(elm); IInternalService is = BasicServiceInvocationHandler.createProvidedServiceProxy( getInternalAccess(), getComponentAdapter(), service, null, type, BasicServiceInvocationHandler.PROXYTYPE_DECOUPLED, null, isCopy(), isRealtime(), getModel().getResourceIdentifier(), moni, null); return is; }