本文整理汇总了Java中org.jgroups.util.Util.close方法的典型用法代码示例。如果您正苦于以下问题:Java Util.close方法的具体用法?Java Util.close怎么用?Java Util.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start() throws Exception {
ch=new JChannel(props);
if(name != null)
ch.setName(name);
execution_service=new ExecutionService(ch);
runner=new ExecutionRunner(ch);
ch.connect("executing-cluster");
JmxConfigurator.registerChannel(ch, Util.getMBeanServer(),
"execution-service", ch.getClusterName(), true);
// Start a consumer
queue.add(executor.submit(runner));
random = new Random();
printValues = false;
try {
loop();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
Util.close(ch);
}
}
示例2: stop
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void stop() {
if(reaper != null)
reaper.stop();
lock.lock();
try {
for(Iterator<Entry<Address,V>> i = conns.entrySet().iterator();i.hasNext();) {
Entry<Address,V> e = i.next();
Util.close(e.getValue());
}
clear();
}
finally {
lock.unlock();
}
conn_listeners.clear();
}
示例3: getState
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void getState(OutputStream ostream) throws Exception {
K key;
V val;
HashMap<K,V> copy=new HashMap<>();
ObjectOutputStream oos=null;
for(Map.Entry<K,V> entry:entrySet()) {
key=entry.getKey();
val=entry.getValue();
copy.put(key, val);
}
try {
oos=new ObjectOutputStream(new BufferedOutputStream(ostream, 1024));
oos.writeObject(copy);
}
finally {
Util.close(oos);
}
}
示例4: retainAll
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* Removes all connections which are not in current_mbrs
*
* @param current_mbrs
*/
public void retainAll(Collection<Address> current_mbrs) {
if(current_mbrs == null)
return;
Map<Address,V> copy=null;
lock.lock();
try {
copy=new HashMap<>(conns);
conns.keySet().retainAll(current_mbrs);
}
finally {
lock.unlock();
}
copy.keySet().removeAll(current_mbrs);
for(Iterator<Entry<Address,V>> i = copy.entrySet().iterator();i.hasNext();) {
Entry<Address,V> e = i.next();
Util.close(e.getValue());
}
copy.clear();
}
示例5: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
System.out.println("MemcachedConnector listening on " + srv_sock.getLocalSocketAddress());
while(thread != null && Thread.currentThread().equals(thread)) {
Socket client_sock=null;
try {
client_sock=srv_sock.accept();
// System.out.println("ACCEPT: " + client_sock.getRemoteSocketAddress());
final RequestHandler handler=new RequestHandler(client_sock);
/*new Thread() {
public void run() {
handler.run();
}
}.start();
*/
thread_pool.execute(handler);
}
catch(ClosedSelectorException closed) {
Util.close(client_sock);
break;
}
catch(Throwable e) {
}
}
}
示例6: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
if(log.isDebugEnabled())
log.debug(local_addr + ": StateProviderAcceptor listening at " + getServerSocketAddress());
while(running) {
try {
final Socket socket=serverSocket.accept();
try {
pool.execute(new Runnable() {
public void run() {
process(socket);
}
});
}
catch(RejectedExecutionException rejected) {
Util.close(socket);
}
}
catch(Throwable e) {
if(serverSocket.isClosed())
running=false;
}
}
}
示例7: getState
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void getState(OutputStream output) throws Exception {
DataOutputStream out=new DataOutputStream(new BufferedOutputStream(output, 1000));
try {
synchronized(nodes) {
Util.objectToStream(nodes, out);
}
}
finally {
Util.close(out);
}
}
示例8: testWriteExceedingCapacity
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void testWriteExceedingCapacity() throws IOException {
final BlockingInputStream in=new BlockingInputStream(10);
new Thread() {
public void run() {
byte[] tmp=new byte[20];
int num=0;
try {
while(true) {
int read=in.read(tmp);
if(read == -1)
break;
num+=read;
}
System.out.println("read " + num + " bytes");
}
catch(IOException e) {
e.printStackTrace();
}
}
}.start();
byte[] buffer=new byte[15];
try {
in.write(buffer);
}
finally {
Util.close(in);
}
}
示例9: testVirtualSynchrony
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void testVirtualSynchrony() throws Exception {
JChannel a = createChannel("A");
Cache cache_1 = new Cache(a, "cache-1");
a.connect("testVirtualSynchrony");
JChannel b = createChannel("B");
Cache cache_2 = new Cache(b, "cache-2");
b.connect("testVirtualSynchrony");
Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b);
// start adding messages
flush(a); // flush all pending message out of the system so everyone receives them
for(int i = 1; i <= 20;i++) {
if(i % 2 == 0)
cache_1.put(i, true); // even numbers
else
cache_2.put(i, true); // odd numbers
}
System.out.println("Starting flush on C1");
flush(a);
System.out.println("Starting flush on C2");
flush(b);
System.out.println("flush done");
System.out.println("cache_1 (" + cache_1.size()
+ " elements): "
+ cache_1
+ "\ncache_2 ("
+ cache_2.size()
+ " elements): "
+ cache_2);
Assert.assertEquals(cache_1.size(), 20, "cache 1: " + cache_1);
Assert.assertEquals(cache_2.size(), 20, "cache 2: " + cache_2);
Util.close(b,a);
}
示例10: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start(String props, String name) throws Exception {
ch=new JChannel(props);
ch.setName(name);
ch.setReceiver(this);
ch.connect("FlowControlTest");
loop();
Util.close(ch);
}
示例11: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void start(boolean direct) throws Exception {
selector=Selector.open();
ch=ServerSocketChannel.open();
ch.bind(new InetSocketAddress("0.0.0.0", 7500));
ch.configureBlocking(false);
ch.register(selector, SelectionKey.OP_ACCEPT, null);
System.out.println("-- server ready");
while(running) {
selector.select();
Set<SelectionKey> keys=selector.selectedKeys();
for(Iterator<SelectionKey> it=keys.iterator(); it.hasNext();) {
SelectionKey key=it.next();
if(!key.isValid()) {
it.remove();
continue;
}
it.remove();
if(key.isAcceptable()) {
SocketChannel client_ch=ch.accept();
System.out.printf("accepted connection from %s\n", client_ch.getRemoteAddress());
client_ch.configureBlocking(false);
client_ch.register(selector, SelectionKey.OP_READ, create(SIZE, direct));
}
else if(key.isReadable()) {
if(!handle((SocketChannel)key.channel(), (ByteBuffer)key.attachment())) {
key.cancel();
Util.close(key.channel());
}
}
}
}
Util.close(selector,ch);
}
示例12: loadProperties
import org.jgroups.util.Util; //导入方法依赖的package包/类
private void loadProperties(File file) {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
properties.load(fis);
} catch (IOException e) {
log.error("An error occurred while loading properties from " + file, e);
} finally {
Util.close(fis);
}
}
示例13: tearDown
import org.jgroups.util.Util; //导入方法依赖的package包/类
@AfterMethod(alwaysRun=true)
void tearDown() throws Exception {
Util.close(channel, coordinator);
}
示例14: tearDown
import org.jgroups.util.Util; //导入方法依赖的package包/类
@AfterMethod
void tearDown() throws Exception {
Util.close(channels);
}
示例15: cleanup
import org.jgroups.util.Util; //导入方法依赖的package包/类
@AfterMethod void cleanup() {
Util.close(b,a);
}