001package com.basilv.examples.rmi; 002 003 004import java.rmi.Naming; 005 006public class TaskExecutorClient { 007 008 public static void main(String[] args) throws Exception { 009 010 String host = "localhost"; 011 int portNumber = 1099; 012 String lookupName = "//" + host + ":" + portNumber + "/" + TaskExecutorServer.REGISTRY_NAME; 013 RemoteTaskExecutor executor = (RemoteTaskExecutor) Naming.lookup(lookupName); 014 015 long currentTimeMillis = System.currentTimeMillis(); 016 System.out.println("Requesting task execution for " + currentTimeMillis); 017 Object result = executor.executeTask(new TestTask(), currentTimeMillis); 018 System.out.println("Task executed for " + result); 019 020 } 021 022 public static class TestTask implements Task { 023 024 public Object execute(Object argument) { 025 System.out.println("Executing task for " + argument + 026 " thread id = " + Thread.currentThread().getId()); 027 try { 028 Thread.sleep(10000); 029 } catch (InterruptedException e) { 030 // Do nothing. 031 } 032 System.out.println("Executed task for " + argument); 033 return argument; 034 } 035 036 } 037}