public Logger execute(Void args) { return getComponent().getLogger(); } }));
/** * Create an instance of the feature. */ public IComponentFeature createInstance(IInternalAccess access, ComponentCreationInfo info) { return new ExecutionComponentFeature(access, info); }
/** * Kill is only invoked, when shutdown of some (e.g. other) feature does not return due to timeout. * The feature should do any kind of possible cleanup, but no asynchronous operations. */ @Override public void kill() { doCleanup(new ThreadDeath()); }
System.err.println(getComponent().getComponentIdentifier()+": double execution"+" "+Thread.currentThread()+" "+componentthread); new RuntimeException("executing: "+getComponent().getComponentIdentifier()).printStackTrace(); ClassLoader cl = setExecutionState(); if(!priostep && stepfuture==null && !IComponentDescription.STATE_SUSPENDED.equals(getComponent().getComponentDescription().getState()) && getComponent().getComponentDescription().getBreakpoints().length>0) if(isAtBreakpoint(getComponent().getComponentDescription().getBreakpoints())) stepi = removeStep(); if((IComponentDescription.STATE_ACTIVE.equals(getComponent().getComponentDescription().getState()))) stepi = removeStep(); publishStepEvent(sti, IMonitoringEvent.EVENT_TYPE_DISPOSAL); found = true; break; getComponent().getLogger().warning("Step not found with id: "+stepinfo+"\n"); stepi = removeStep(); cms.suspendComponent(getComponent().getComponentDescription().getName()); int endstart = ((IInternalExecutionFeature)getComponent().getComponentFeature(IExecutionFeature.class)).getEndstateStart(); boolean stateok = priostep || endstart==-1 || step.getStepCount()>=endstart;
if(!isComponentThread()) beforeBlock(); waitForDelay(timeout, realtime) .addResultListener(new IResultListener<Void>() 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(); afterBlock();
final Future<T> ret = createStepFuture(step); if(IComponentDescription.STATE_TERMINATED.equals(getComponent().getComponentDescription().getState())) ret.setException(new ComponentTerminatedException(getComponent().getComponentIdentifier())); addStep(new StepInfo(step, ret, new ThreadLocalTransferHelper(true), prio, stepcnt++)); wakeup();
IExecutionFeature exef = getComponent().getComponentFeature0(IExecutionFeature.class); if(exef instanceof ExecutionComponentFeature) List<StepInfo> steps = ((ExecutionComponentFeature)exef).getCurrentSteps(); if(steps!=null) MonitoringEvent event = new MonitoringEvent(getComponent().getComponentIdentifier(), getComponent().getComponentDescription().getCreationTime(), step.getStep().toString(), IMonitoringEvent.EVENT_TYPE_CREATION+"."+TYPE_STEP, null, System.currentTimeMillis(), PublishEventLevel.FINE); event.setProperty("details", getStepDetails(step)); event.setProperty("id", step.getStepCount()); ret.add(event);
SServiceProvider.getService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM, false) .addResultListener(createResultListener(new ExceptionDelegationResultListener<IClockService, T>(ret)
/** * 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; }
/** * 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); } }
SServiceProvider.getService(getComponent(), IClockService.class, RequiredServiceInfo.SCOPE_PLATFORM, false) .addResultListener(createResultListener(new ExceptionDelegationResultListener<IClockService, Void>(ret)
/** * Get the string representation. */ public String toString() { return "ExecutionFeature("+getComponent().getComponentIdentifier()+")"; } }
public void customResultAvailable(Void result) { doCleanup(new StepAborted()); super.customResultAvailable(result); } });
/** * 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()
/** * 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(); } } }); } } });