org.jgroups.util.Util类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中org.jgroups.util.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util

Util介绍

[英]Collection of various utility routines that can not be assigned to other classes.
[中]无法分配给其他类的各种实用程序例程的集合。

代码示例

代码示例来源:origin: wildfly/wildfly

public static void assertEquals(Object val1,Object val2) {
  assertEquals(null,val1,val2);
}

代码示例来源:origin: wildfly/wildfly

public static void assertFalse(boolean condition) {
  assertFalse(null,condition);
}

代码示例来源:origin: wildfly/wildfly

protected void applyNewConfig(byte[] buffer) {
  final InputStream in=new ByteArrayInputStream(buffer);
  Thread thread=new Thread(() -> {
    try {
      JChannel ch=new JChannel(in);
      Util.sleepRandom(1000, 5000);
      channel.disconnect();
      JChannel tmp=channel;
      channel=ch;
      channel.setName(name);
      channel.setReceiver(MPerf.this);
      channel.connect("mperf");
      local_addr=channel.getAddress();
      JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
      Util.close(tmp);
      JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
    }
    catch(Exception e) {
      System.err.println("failed creating new channel");
    }
  });
  System.out.println("<< restarting channel");
  thread.start();
}

代码示例来源:origin: wildfly/wildfly

public void writeTo(DataOutput out) throws Exception {
  out.writeByte(type);
  Util.writeAddresses(mbrs, out);
  Util.writeAddress(from, out);
}

代码示例来源:origin: wildfly/wildfly

public void readFrom(DataInput in) throws Exception {
  type=in.readByte();
  mbr=Util.readAddress(in);
  sock_addr=Util.readStreamable(IpAddress::new, in);
  int size=in.readInt();
  if(size > 0) {
    mbrs=new HashSet<>();
    for(int i=0; i < size; i++)
      mbrs.add(Util.readAddress(in));
  }
}

代码示例来源:origin: wildfly/wildfly

private void loadProperties(File file) {
  FileInputStream fis = null;
  try {
    fis = new FileInputStream(file);
    properties.load(fis);
  } catch (IOException e) {
    log.error(Util.getMessage("AnErrorOccurredWhileLoadingPropertiesFrom") + file, e);
  } finally {
    Util.close(fis);
  }
}

代码示例来源:origin: wildfly/wildfly

public void start() throws Exception {
  try {
    ch=new JChannel(props);
    if(name != null)
      ch.setName(name);
    lock_service=new LockService(ch);
    lock_service.addLockListener(this);
    ch.connect("lock-cluster");
    JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
    loop();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  finally {
    Util.close(ch);
  }
}

代码示例来源:origin: wildfly/wildfly

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);
}

代码示例来源:origin: wildfly/wildfly

public void start(String props, boolean jmx, String name) throws Exception {
  channel=new JChannel(props).name(name);
  disp=new RpcDispatcher(channel, this) // no concurrent processing on incoming method calls
   .setMembershipListener(this).setMethodLookup(id -> METHODS[0]);
  if(jmx) {
    MBeanServer srv=Util.getMBeanServer();
    if(srv == null)
      throw new Exception("No MBeanServers found");
    JmxConfigurator.registerChannel(channel, srv, "jgroups", channel.getClusterName(), true);
  }
  channel.connect("rpc-speed-test");
  View view=channel.getView();
  if(view.size() > 2)
    System.err.printf("More than 2 members in cluster: %s; terminating\n", view);
  else
    loop();
  Util.close(disp, channel);
}

代码示例来源:origin: wildfly/wildfly

public static List<Message> readMessageList(DataInput in, short transport_id) throws Exception {
  List<Message> list=new LinkedList<>();
  Address dest=Util.readAddress(in);
  Address src=Util.readAddress(in);
  // AsciiString cluster_name=Bits.readAsciiString(in); // not used here
  short length=in.readShort();
  byte[] cluster_name=length >= 0? new byte[length] : null;
  if(cluster_name != null)
    in.readFully(cluster_name, 0, cluster_name.length);
  int len=in.readInt();
  for(int i=0; i < len; i++) {
    Message msg=new Message(false);
    msg.readFrom(in);
    msg.setDest(dest);
    if(msg.getSrc() == null)
      msg.setSrc(src);
    // Now add a TpHeader back on, was not marshalled. Every message references the *same* TpHeader, saving memory !
    msg.putHeader(transport_id, new TpHeader(cluster_name));
    list.add(msg);
  }
  return list;
}

代码示例来源:origin: wildfly/wildfly

protected void start(String props, String name) throws Exception {
  channel=new JChannel(props).name(name);
  // TP transport=channel.getProtocolStack().getTransport();
  // transport.setThreadPool(new DirectExecutor());
  disp=new RpcDispatcher(channel, this).setMembershipListener(this);
  disp.setMethodLookup(ignored -> requestMethod);
  channel.connect("rt");
  View view=channel.getView();
  if(view.size() > 2)
    System.err.printf("More than 2 members found (%s); terminating\n", view);
  else
    loop();
  Util.close(channel, disp);
}

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

Address              sender=msg.getSrc();
Message              assembled_msg;
byte[]               m;
m=frag_table.add(hdr.id, hdr.frag_id, hdr.num_frags, msg.getBuffer());
if(m != null) {
  try {
    bis=new ByteArrayInputStream(m);
    in=new DataInputStream(bis);
    assembled_msg=new Message(false);
    assembled_msg.readFrom(in);
    if(log.isTraceEnabled()) log.trace("assembled_msg is " + assembled_msg);
    assembled_msg.setSrc(sender); // needed ? YES, because fragments have a null src !!
    num_received_msgs++;
    up_prot.up(new Event(Event.MSG, assembled_msg));
    Util.close(in);

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

FragHeader         hdr;
Message            frag_msg;
Address            dest=msg.getDest(), src=msg.getSrc();
long               id=curr_id++; // used as seqnos
int                num_frags;
    bos.reset();
    out=new DataOutputStream(bos);
    msg.writeTo(out);
    out.flush();
    buffer=bos.getRawBuffer();
    fragments=Util.fragmentBuffer(buffer, frag_size, bos.size());
    hdr=new FragHeader(id, i, num_frags);
    frag_msg.putHeader(name, hdr);
    evt=new Event(Event.MSG, frag_msg);
    down_prot.down(evt);
  Util.close(out);

代码示例来源:origin: wildfly/wildfly

Address dest=Util.readAddress(in);
Address src=Util.readAddress(in);
short length=in.readShort();
byte[] cluster_name=length >= 0? new byte[length] : null;
  Message msg=new Message(false);
  msg.readFrom(in);
  msg.setDest(dest);
  if(msg.getSrc() == null)
    msg.setSrc(src);

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

int     type=evt.getType();
Message msg;
  msg=(Message)evt.getArg();
  if(!receive_local_msgs) {  // discard local messages (sent by myself to me)
    if(local_addr != null && msg.getSrc() != null)
      if(local_addr.equals(msg.getSrc()))
        return null;
  View tmp=(View)evt.getArg();
  if(tmp instanceof MergeView)
    my_view=new View(tmp.getVid(), tmp.getMembers());
    log.warn("Channel has STREAMING_STATE_TRANSFER, however," +
         " application does not implement ExtendedMessageListener. State is not transfered");
    Util.close(is);        		     		        	
  handleExit(evt);
  return null;  // no need to pass event up; already done in handleExit()
    log.warn("Channel has STREAMING_STATE_TRANSFER, however," +
         " application does not implement ExtendedMessageListener. State is not transfered");        		
    Util.close(os);

代码示例来源:origin: wildfly/wildfly

public void start(JChannel ch) throws Exception {
  this.ch=ch;
  lock_service=new LockService(ch);
  lock_service.addLockListener(this);
  ch.connect("lock-cluster");
  JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
  try {
    loop();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  finally {
    Util.close(ch);
  }
}

代码示例来源:origin: wildfly/wildfly

protected void stop() {
  log.info("%s: leaving bridge cluster '%s'", channel.getAddress(), channel.getClusterName());
  Util.close(channel);
}

代码示例来源:origin: wildfly/wildfly

protected void setStateInApplication(InputStream in, Object resource, final Address provider) {
  log.debug("%s: setting the state in the aplication", local_addr);
  try {
    up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, in));
    up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM_CLOSED, new StateTransferResult()));
    down_prot.down(new Event(Event.GET_VIEW_FROM_COORD)); // https://issues.jboss.org/browse/JGRP-1751
  }
  catch(Throwable t) {
    handleException(t);
  }
  finally {
    Util.close(in);
    close(resource);
    if(isDigestNeeded()) {
      openBarrierAndResumeStable();
      closeHoleFor(provider);
    }
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from
 * the view until failure detection has kicked in and the new coord installed the new view
 */
public static void shutdown(JChannel ch) throws Exception {
  DISCARD discard=new DISCARD();
  discard.setLocalAddress(ch.getAddress());
  discard.setDiscardAll(true);
  ProtocolStack stack=ch.getProtocolStack();
  TP transport=stack.getTransport();
  stack.insertProtocol(discard,ProtocolStack.Position.ABOVE,transport.getClass());
  //abruptly shutdown FD_SOCK just as in real life when member gets killed non gracefully
  FD_SOCK fd=ch.getProtocolStack().findProtocol(FD_SOCK.class);
  if(fd != null)
    fd.stopServerSocket(false);
  View view=ch.getView();
  if(view != null) {
    ViewId vid=view.getViewId();
    List<Address> members=Collections.singletonList(ch.getAddress());
    ViewId new_vid=new ViewId(ch.getAddress(),vid.getId() + 1);
    View new_view=new View(new_vid,members);
    // inject view in which the shut down member is the only element
    GMS gms=stack.findProtocol(GMS.class);
    gms.installView(new_view);
  }
  Util.close(ch);
}

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

private List<Message> readMessageList(DataInputStream instream, Address dest, boolean multicast) throws Exception {
  List<Message> list=new LinkedList<Message>();
  int           len;
  Message       msg;
  Address       src;
  len=instream.readInt();
  src=Util.readAddress(instream);
  for(int i=0; i < len; i++) {
    msg=new Message(false); // don't create headers, readFrom() will do this
    msg.readFrom(instream);
    postUnmarshallingList(msg, dest, multicast);
    msg.setSrc(src);
    list.add(msg);
  }
  return list;
}

相关文章

Util类方法