39 lines
1019 B
Java
39 lines
1019 B
Java
/*
|
|
* Copyright (c) 2011 Tony Garnock-Jones. All rights reserved.
|
|
*/
|
|
|
|
package hop;
|
|
|
|
import java.io.IOException;
|
|
import java.util.UUID;
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
|
/**
|
|
*/
|
|
public class Subscription {
|
|
public ServerApi _api;
|
|
public String _source;
|
|
public Object _filter;
|
|
public String _consumerName;
|
|
public HalfQueue _consumer;
|
|
public Object _subscriptionToken;
|
|
|
|
public Subscription(ServerApi api, String source, Object filter) throws InterruptedException, IOException {
|
|
_api = api;
|
|
_source = source;
|
|
_filter = filter;
|
|
_consumerName = UUID.randomUUID().toString();
|
|
_consumer = new HalfQueue();
|
|
_api._container.bind(_consumerName, _consumer);
|
|
_subscriptionToken = _api.subscribe(source, filter, _consumerName);
|
|
}
|
|
|
|
public BlockingQueue<Object> getQueue() {
|
|
return _consumer.getQueue();
|
|
}
|
|
|
|
public void unsubscribe() throws IOException {
|
|
_api.unsubscribe(_source, _subscriptionToken);
|
|
}
|
|
}
|