public Logger execute(Void args) { return getComponent().getLogger(); } }));
/** * Get the string representation. */ public String toString() { return "ExecutionFeature("+getComponent().getComponentIdentifier()+")"; } }
/** * Set flags when entering thread. * @return The previous context class loader. */ protected ClassLoader setExecutionState() { // Remember execution thread. this.componentthread = Thread.currentThread(); IComponentIdentifier.LOCAL.set(getComponent().getComponentIdentifier()); IInternalExecutionFeature.LOCAL.set(getComponent()); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(component.getClassLoader()); ISuspendable.SUSPENDABLE.set(new ComponentSuspendable(getComponent())); return cl; }
/** * Test if current thread is the component thread. * @return True if the current thread is the component thread. */ public boolean isComponentThread() { return Thread.currentThread()==componentthread || IComponentDescription.STATE_TERMINATED.equals(getComponent().getComponentDescription().getState()) && Starter.isRescueThread(getComponent().getComponentIdentifier()); }
public void customResultAvailable(Object result) { if(step.getPriority()<STEP_PRIORITY_IMMEDIATE && getComponent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getComponent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) { getComponent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), IMonitoringEvent.EVENT_TYPE_DISPOSAL+"." +IMonitoringEvent.SOURCE_CATEGORY_EXECUTION, null, System.currentTimeMillis(), PublishEventLevel.FINE), PublishTarget.TOALL); // null was step.getCause() } super.customResultAvailable(result); } });
/** * Wait for the next tick. * @param time The time. */ public IFuture<Void> waitForTick() { final Future<Void> ret = new Future<Void>(); IClockService cs = SServiceProvider.getLocalService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM); final ITimer[] ts = new ITimer[1]; ts[0] = cs.createTickTimer(new ITimedObject() { public void timeEventOccurred(final long currenttime) { ret.setResult(null); } }); if(timers==null) timers = new ArrayList<ITimer>(); timers.add(ts[0]); return ret; }
IClockService cs = SServiceProvider.getLocalService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM); final ITimer[] ts = new ITimer[1]; ts[0] = cs.createTickTimer(new ITimedObject()
/** * Publish a step event. */ public void publishStepEvent(StepInfo step, String type) { if(step.getPriority()<IExecutionFeature.STEP_PRIORITY_IMMEDIATE && getComponent().getComponentFeature0(IMonitoringComponentFeature.class)!=null && getComponent().getComponentFeature(IMonitoringComponentFeature.class).hasEventTargets(PublishTarget.TOALL, PublishEventLevel.FINE)) { MonitoringEvent event = new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), type+"."+TYPE_STEP, null, System.currentTimeMillis(), PublishEventLevel.FINE); // null was step.getCause() event.setProperty("sourcename", SReflect.getUnqualifiedClassName(step.getStep().getClass())); event.setProperty("details", getStepDetails(step)); event.setProperty("id", step.getStepCount()); getComponent().getComponentFeature(IMonitoringComponentFeature.class).publishEvent(event, PublishTarget.TOALL); } }
/** * Do a step of a suspended component. */ public IFuture<Void> doStep(String stepinfo) { Future<Void> ret = new Future<Void>(); synchronized(this) { if(!IComponentDescription.STATE_SUSPENDED.equals(getComponent().getComponentDescription().getState())) { ret.setException(new IllegalStateException("Component not suspended: "+getComponent().getComponentIdentifier())); } else if(this.stepinfo!=null || stepfuture!=null) { ret.setException(new RuntimeException("Only one step allowed at a time.")); } else { // this.dostep = true; this.stepfuture = ret; this.stepinfo = stepinfo; } } wakeup(); return ret; }
/** * Check if no agent is running whenever the clock advances. */ protected static void monitorExecution(IExternalAccess ea, IExecutionService exe) { // System.out.println("Monitoring execution..."); IExecutable[] tasks = exe.getRunningTasks(); for(IExecutable task: tasks) { // Only print warning for sub-components if(task instanceof ExecutionComponentFeature) { IComponentIdentifier cid = ((ExecutionComponentFeature)task).getComponent().getComponentIdentifier(); IComponentIdentifier test = cid; while(test!=null && !test.equals(ea.getComponentIdentifier())) { test = test.getParent(); } if(test!=null && !cid.equals(ea.getComponentIdentifier())) { System.out.println("Non-idle component at time switch: "+cid); } } } } }
public void exceptionOccurred(Exception exception) { available = false; // Happens during platform bootstrapping -> execute on platform rescue thread. if(!bootstrap) { bootstrap = true; Starter.scheduleRescueStep(getComponent().getComponentIdentifier().getRoot(), new Runnable() { public void run() { boolean again = true; while(!available && again) { again = execute(); } bootstrap = false; if(again) { // Bootstrapping finished -> do real kickoff wakeup(); } } }); } } });
IExecutionFeature exef = getComponent().getComponentFeature0(IExecutionFeature.class); if(exef instanceof ExecutionComponentFeature) MonitoringEvent event = new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), IMonitoringEvent.EVENT_TYPE_CREATION+"."+TYPE_STEP, null, System.currentTimeMillis(), PublishEventLevel.FINE);
if(IComponentDescription.STATE_TERMINATED.equals(getComponent().getComponentDescription().getState())) assert threaddeath || !IComponentDescription.STATE_TERMINATED.equals(getComponent().getComponentDescription().getState()); System.err.println(getComponent().getComponentIdentifier()+": double execution"); new RuntimeException("executing: "+getComponent().getComponentIdentifier()).printStackTrace();
if(IComponentDescription.STATE_TERMINATED.equals(getComponent().getComponentDescription().getState())) ret.setException(new ComponentTerminatedException(getComponent().getComponentIdentifier()));
SServiceProvider.getService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM, false) .addResultListener(createResultListener(new ExceptionDelegationResultListener<IClockService, T>(ret)
SServiceProvider.getService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM, false) .addResultListener(createResultListener(new ExceptionDelegationResultListener<IClockService, Void>(ret)
if(getComponent().getComponentDescription().isSynchronous()) IComponentManagementService cms = SServiceProvider.getLocalService(getComponent(), IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM, false); cms.getExternalAccess(getComponent().getComponentIdentifier().getParent()) .addResultListener(new DefaultResultListener<IExternalAccess>()
System.err.println(getComponent().getComponentIdentifier()+": double execution"+" "+Thread.currentThread()+" "+componentthread); new RuntimeException("executing: "+getComponent().getComponentIdentifier()).printStackTrace(); if(!priostep && stepfuture==null && !IComponentDescription.STATE_SUSPENDED.equals(getComponent().getComponentDescription().getState()) && getComponent().getComponentDescription().getBreakpoints().length>0) if(isAtBreakpoint(getComponent().getComponentDescription().getBreakpoints())) if((IComponentDescription.STATE_ACTIVE.equals(getComponent().getComponentDescription().getState()))) getComponent().getLogger().warning("Step not found with id: "+stepinfo+"\n"); cms.suspendComponent(getComponent().getComponentDescription().getName()); int endstart = ((IInternalExecutionFeature)getComponent().getComponentFeature(IExecutionFeature.class)).getEndstateStart(); boolean stateok = priostep || endstart==-1 || step.getStepCount()>=endstart; getComponent().getLogger().warning(!stateok? "Step omitted due to endstate:"+" "+step.getStep(): "Step invalid "+" "+step.getStep()); ex = new StepAborted(); getComponent().getLogger().warning("Component step threw hard exception: "+step.getStep()+"\n"+sw); getComponent().getLogger().severe("Component step failed: "+step.getStep()+"\n"+sw); getComponent().getLogger().severe("Component step listener failed: "+step.getStep()+"\n"+sw); if(IComponentDescription.STATE_ACTIVE.equals(getComponent().getComponentDescription().getState()) || stepfuture!=null) getComponent().getLogger().severe("Component cycle failed:\n"+sw);