public MonitoredExertDispatcher( Exertion exertion, Set<Context> sharedContext, boolean isSpawned, Provider provider) throws Exception { super(exertion, sharedContext, isSpawned, provider, null); if (sessionMonitor == null) sessionMonitor = (MonitoringManagement) ProviderAccessor.getProvider( Sorcer.getActualName(Sorcer.getExertMonitorName()), MonitoringManagement.class); if (lrm == null) lrm = new LeaseRenewalManager(); // get the exertion with the monitor session this.xrt = (ServiceExertion) register(exertion); // make the monitor session of this exertion active logger.log(Level.FINER, "Dispatching task now: " + xrt.getName()); MonitoringSession session = (MonitoringSession) (xrt.getMonitorSession()); session.init((Monitorable) provider.getProxy(), LEASE_RENEWAL_PERIOD, DEFAULT_TIMEOUT_PERIOD); lrm.renewUntil(session.getLease(), Lease.ANY, null); dThread = new DispatchThread(); try { dThread.start(); dThread.join(); } catch (InterruptedException ie) { ie.printStackTrace(); state = FAILED; } }
private Exertion register(Exertion exertion) throws Exception { RemoteEventListener l = (RemoteEventListener) (new ResultListener().export()); ServiceExertion registeredExertion = (ServiceExertion) (sessionMonitor.register(l, exertion, LEASE_RENEWAL_PERIOD)); MonitoringSession session = (MonitoringSession) (registeredExertion.getMonitorSession()); logger.info("Session for the exertion =" + session); logger.info( "Lease to be renewed for duration =" + (session.getLease().getExpiration() - System.currentTimeMillis())); lrm.renewUntil(session.getLease(), Lease.ANY, null); return registeredExertion; }
// Made private so that other classes just calls execExertion and not // execTask private void execTask(NetTask task) throws ExertionException, SignatureException { logger.log(Level.INFO, "start executing task"); try { Service provider = ProviderAccessor.getProvider( task.getProcessSignature().getProviderName(), task.getServiceType()); logger.log(Level.INFO, "got a provider:" + provider); if (provider == null) { String msg = null; // get the PROCESS Method and grab provider name + interface NetSignature method = (NetSignature) task.getProcessSignature(); msg = "No Provider available. Provider Name: " + method.getProviderName() + " Provider interface: " + method.getServiceType(); System.err.println(msg); throw new ExertionException(msg, task); } else { // setTaskProvider(task, provider.getProviderName()); logger.log(Level.INFO, "Servicing task now .............."); MonitoringSession session = (MonitoringSession) (task.getMonitorSession()); session.init((Monitorable) provider, LEASE_RENEWAL_PERIOD, DEFAULT_TIMEOUT_PERIOD); lrm.renewUntil(session.getLease(), Lease.ANY, null); task.setService(provider); provider.service(task, null); } } catch (RemoteException re) { re.printStackTrace(); logger.log(Level.SEVERE, "dispatcher execution failed for task: " + task); throw new ExertionException("Remote Exception while executing task"); } catch (MonitorException mse) { mse.printStackTrace(); logger.log(Level.SEVERE, "dispatcher execution failed for task: " + task); throw new ExertionException("Remote Exception while executing task"); } catch (TransactionException te) { te.printStackTrace(); logger.log(Level.SEVERE, "dispatcher execution failed for task: " + task); throw new ExertionException("Remote Exception while executing task"); } }