public OpenImpl(String name) { this.name = name; publisherName = name; stateEventTypeName = "_" + name + "_state"; state = s0; ClientConfig config = new DefaultClientConfig(); client = Client.create(config); service = client.resource(REST_URI); eventTypeService = service.path(EVENTS_PATH); publishersService = service.path(PUBLISHERS_PATH); myPublisher = service.path(PUBLISHERS_PATH + "/" + publisherName); System.out.println("Registering events"); ClientResponse response = eventTypeService .type(MediaType.APPLICATION_XML) .put(ClientResponse.class, CopalClient.eventType(stateEventTypeName)); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); System.out.println("Setting ttl"); WebResource test = service.path(EVENTS_PATH + "/" + stateEventTypeName + "/ttl"); response = test.type(MediaType.TEXT_PLAIN).put(ClientResponse.class, "" + Integer.MAX_VALUE); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); String[] eventNames = {stateEventTypeName}; System.out.println("Registering publisher"); System.out.println(CopalClient.publisher(publisherName, eventNames)); response = publishersService .type(MediaType.APPLICATION_XML) .put(ClientResponse.class, CopalClient.publisher(publisherName, eventNames)); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); response = myPublisher .type(MediaType.APPLICATION_XML) .post(ClientResponse.class, CopalClient.event(stateEventTypeName, state)); System.out.println(response.toString()); Runtime.getRuntime() .addShutdownHook( new Thread() { public void run() { System.out.println("Removing publisher"); ClientResponse response = myPublisher.delete(ClientResponse.class); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); System.out.println("Removing events"); WebResource wr = service.path(EVENTS_PATH + "/" + stateEventTypeName); response = wr.delete(ClientResponse.class); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); } }); }
@Override public boolean a() { System.out.println("svolgo azione a"); state = s0; ClientResponse response = myPublisher .type(MediaType.APPLICATION_XML) .post(ClientResponse.class, CopalClient.event(stateEventTypeName, state)); System.out.println(response.toString()); return true; }