当前位置: 首页>>代码示例>>Java>>正文


Java Util类代码示例

本文整理汇总了Java中org.jgroups.util.Util的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Util类属于org.jgroups.util包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _getProperty

import org.jgroups.util.Util; //导入依赖的package包/类
private static String _getProperty(String var, String default_value) {
    if(var == null)
        return null;
    List<String> list=Util.parseCommaDelimitedStrings(var);
    if(list == null || list.isEmpty()) {
        list=new ArrayList<String>(1);
        list.add(var);
    }
    String retval=null;
    for(String prop: list) {
        try {
            retval=ApplicationProperties.getProperty(prop);
            if(retval != null)
                return retval;
        }
        catch(Throwable e) {
        }
    }
    return default_value;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:21,代码来源:JGroupsUtils.java

示例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();
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:AbstractConnectionMap.java

示例3: start

import org.jgroups.util.Util; //导入依赖的package包/类
private void start(boolean server, int num, int msg_size, String props) throws Exception {
    this.server=server;
    this.num=num;
    this.msg_size=msg_size;
    this.props=props;

    channel=new JChannel(props);
    channel.setReceiver(this);
    channel.connect("rt");

    if(server) {
        System.out.println("server started (ctrl-c to kill)");
        while(true) {
            Util.sleep(60000);
        }
    }
    else {
        channel.setDiscardOwnMessages(true);
        System.out.println("sending " + num + " requests");
        sendRequests();
        channel.close();
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:24,代码来源:RoundTrip.java

示例4: setState

import org.jgroups.util.Util; //导入依赖的package包/类
public void setState(InputStream istream) throws Exception {
    total_received=0;
    int received=0;
    while(true) {
        byte[] buf=new byte[10000];
        received=istream.read(buf);
        if(received < 0)
            break;
        if(delay > 0)
            Util.sleep(delay);
        total_received+=received;
        if(requester_fails)
            throw new Exception("booom - requester failed");
    }

    stop=System.currentTimeMillis();
    System.out.println("<-- received " + Util.printBytes(total_received) + " in " + (stop-start) + "ms");
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:LargeState.java

示例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) {
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:25,代码来源:MemcachedConnector.java

示例6: start

import org.jgroups.util.Util; //导入依赖的package包/类
public void start() throws IOException {
    // https://jira.jboss.org/jira/browse/JGRP-777 - this doesn't work on MacOS, and we don't have
    // cross talking on Windows anyway, so we just do it for Linux. (How about Solaris ?)
    // if(can_bind_to_mcast_addr)
    //   diag_sock=Util.createMulticastSocket(getSocketFactory(),
    //                               Global.TP_DIAG_MCAST_SOCK, diagnostics_addr, diagnostics_port, log);
    //else
    diag_sock=socket_factory.createMulticastSocket("jgroups.tp.diag.mcast_sock", diagnostics_port);
    diag_sock.setTimeToLive(ttl);

    List<NetworkInterface> interfaces=bind_interfaces != null? bind_interfaces : Util.getAllAvailableInterfaces();
    bindToInterfaces(interfaces, diag_sock);

    if(thread == null || !thread.isAlive()) {
        thread=thread_factory.newThread(this, THREAD_NAME);
        thread.setDaemon(true);
        thread.start();
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:20,代码来源:DiagnosticsHandler.java

示例7: removeConnectionIfPresent

import org.jgroups.util.Util; //导入依赖的package包/类
/** Only removes the connection if conns.get(address) == conn */
public void removeConnectionIfPresent(Address address, V conn) {
    if(address == null || conn == null)
        return;

    lock.lock();
    try {
        V existing=conns.get(address);
        if(conn == existing) {
            V tmp=conns.remove(address);
            Util.close(tmp);
        }
    }
    finally {
        lock.unlock();
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:AbstractConnectionMap.java

示例8: testResponsesComplete3

import org.jgroups.util.Util; //导入依赖的package包/类
public void testResponsesComplete3() {
    Address one=new SiteUUID((UUID)Util.createRandomAddress("lon1"), "lon1", "LON");
    Address two=new SiteUUID((UUID)Util.createRandomAddress("sfo1"), "sfo1", "SFO");
    Address three=new SiteUUID((UUID)Util.createRandomAddress("nyc1"), "nyc1", "NYC");

    GroupRequest<Integer> req=new GroupRequest<>(null, null, Arrays.asList(one, two, three), RequestOptions.SYNC());
    req.suspect(one);
    req.receiveResponse(1, one, false);
    req.siteUnreachable("LON");
    checkComplete(req, false);

    req.siteUnreachable("SFO");
    req.receiveResponse(2, two, false);
    req.suspect(two);
    checkComplete(req, false);

    req.siteUnreachable("NYC");
    checkComplete(req, true);
    req.suspect(three);
    checkComplete(req, true);
    req.receiveResponse(3, three, false);
    checkComplete(req, true);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:24,代码来源:GroupRequestTest.java

示例9: setUp

import org.jgroups.util.Util; //导入依赖的package包/类
@BeforeMethod
void setUp() throws Exception {
    channels       = new JChannel[2];
    dispatchers    = new RpcDispatcher[2];
    muxDispatchers = new RpcDispatcher[2][2];

    channels[0] = createChannel(true, 2, "A");
    channels[1] = createChannel(channels[0], "B");
    
    for (int i = 0; i < dispatchers.length; i++) {

        dispatchers[i] = new RpcDispatcher(channels[i], new Server("dispatcher[" + i + "]"));

        channels[i].setUpHandler(new MuxUpHandler(dispatchers[i].getProtocolAdapter()));

        for (int j = 0; j < muxDispatchers[i].length; j++) {
            muxDispatchers[i][j] = new MuxRpcDispatcher((short) j, channels[i], null, null, new Server("muxDispatcher[" + i + "][" + j + "]"));
        }
 
        channels[i].connect("MuxRpcDispatcherTest");

        Util.sleep(1000);
    }

    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, channels);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:27,代码来源:MuxRpcDispatcherTest.java

示例10: setDefaultValues

import org.jgroups.util.Util; //导入依赖的package包/类
public static void setDefaultValues(List<Protocol> protocols) throws Exception {
    if(protocols == null)
        return;

    // check InetAddress related features of stack
    Collection<InetAddress> addrs=getInetAddresses(protocols);
    StackType ip_version=Util.getIpStackType(); // 0 = n/a, 4 = IPv4, 6 = IPv6

    if(!addrs.isEmpty()) {
        // check that all user-supplied InetAddresses have a consistent version:
        // 1. If an addr is IPv6 and we have an IPv4 stack --> FAIL
        // 2. If an address is an IPv4 class D (multicast) address and the stack is IPv6: FAIL
        // Else pass

        for(InetAddress addr : addrs) {
            if(addr instanceof Inet6Address && ip_version == StackType.IPv4)
                throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
            if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
                throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
        }
    }

    // process default values
    setDefaultValues(protocols, ip_version);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:26,代码来源:Configurator.java

示例11: objectFromBuffer

import org.jgroups.util.Util; //导入依赖的package包/类
public Object objectFromBuffer(byte[] buf, int offset, int length) throws Exception {
    if(buf == null)
        return null;

    DataInputStream in=new DataInputStream(new ByteArrayInputStream(buf));
    byte type=in.readByte();
    if(type == NULL)
        return null;
    if(type == METHOD_CALL) {
        short id=in.readShort();
        short len=in.readShort();
        Object[] args=len > 0? new Object[len] : null;
        if(args != null) {
            for(int i=0; i < args.length; i++)
                args[i]=Util.objectFromStream(in);
        }
        return new MethodCall(id, args);
    }
    else if(type == VALUE) {
        long expiration_time=in.readLong();
        Object obj=Util.objectFromStream(in);
        return new Cache.Value(obj, expiration_time);
    }
    else
        return Util.objectFromStream(in);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:27,代码来源:PartitionedHashMap.java

示例12: receive

import org.jgroups.util.Util; //导入依赖的package包/类
public void receive(Message msg) {
    byte type=msg.getRawBuffer()[msg.getOffset()];
    switch(type) {
        case PING:
            final Message rsp=new Message(msg.getSrc(), null, PONG_RSP);
            rsp.setFlag(Message.Flag.DONT_BUNDLE, Message.NO_FC);
            try {
                ch.send(rsp);
            }
            catch(Exception e) {
                e.printStackTrace();
            }
            break;
        case PONG:
            long rtt=System.nanoTime() - start;
            double ms=rtt / 1000.0 / 1000.0;
            System.out.println("RTT for " + msg.getSrc() + ": " + Util.format(ms) + " ms");
            break;
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:PingPong.java

示例13: testSingleChannel

import org.jgroups.util.Util; //导入依赖的package包/类
public void testSingleChannel() throws Exception {
    Semaphore s = new Semaphore(1);
    FlushTestReceiver receivers[] ={ new FlushTestReceiver("c1", s, 0, FlushTestReceiver.CONNECT_ONLY) };
    receivers[0].start();
    s.release(1);

    // Make sure everyone is in sync
    Channel[] tmp = new Channel[receivers.length];
    for (int i = 0; i < receivers.length; i++)
        tmp[i] = receivers[i].getChannel();
    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, tmp);

    // Reacquire the semaphore tickets; when we have them all we know the threads are done
    s.tryAcquire(1, 10, TimeUnit.SECONDS);
    receivers[0].cleanup();
    Util.sleep(1000);

    checkEventStateTransferSequence(receivers[0]);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:20,代码来源:FlushTest.java

示例14: serializedSize

import org.jgroups.util.Util; //导入依赖的package包/类
public int serializedSize() {
    int retval=super.serializedSize();
    retval+=Global.SHORT_SIZE; // for size of subgroups vector
    if(subgroups == null)
        return retval;
    for(View v: subgroups) {
        retval+=Global.SHORT_SIZE + Global.LONG_SIZE // creator and ID (ViewId)
          + Global.SHORT_SIZE; // number of members in the subview

        Address creator=v.getCreator();
        if(get(creator) < 0)
            retval+=Util.size(creator);

        retval+=v.size() * Global.SHORT_SIZE; // a short (index) for each member
        for(Address sub_mbr: v) {
            int index=get(sub_mbr);
            if(index < 0)
                retval+=Util.size(sub_mbr);
        }
    }
    return retval;
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:23,代码来源:MergeView.java

示例15: stop

import org.jgroups.util.Util; //导入依赖的package包/类
public synchronized void stop() {
    Thread tmp=thread;
    thread=null;
    try {
        close_strategy.run();
    }
    catch(Exception e1) {
    }
    finally {
        Util.close(receiver_socket); // second line of defense
    }

    if(tmp != null && tmp.isAlive()) {
        tmp.interrupt();
        try {
            tmp.join(Global.THREAD_SHUTDOWN_WAIT_TIME);
        }
        catch(InterruptedException e) {
            Thread.currentThread().interrupt(); // set interrupt flag again
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:23,代码来源:UDP.java


注:本文中的org.jgroups.util.Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。