本文整理汇总了Java中org.jgroups.View类的典型用法代码示例。如果您正苦于以下问题:Java View类的具体用法?Java View怎么用?Java View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
View类属于org.jgroups包,在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addListener
import org.jgroups.View; //导入依赖的package包/类
public void addListener(@NotNull final JgroupsViewListener viewListener) {
requireNonNull(viewListener);
log.debug("Adding view listener {}...", viewListener);
synchronized (viewListeners) {
if (viewListeners.containsKey(viewListener)) {
throw new IllegalStateException("View listener is already registered.");
}
}
View initialView = jChannel.view();
viewListener.initialView(initialView.getMembers());
synchronized (viewListeners) {
viewListeners.put(viewListener, initialView);
}
}
示例2: viewUpdate
import org.jgroups.View; //导入依赖的package包/类
public void viewUpdate(final View newView) {
requireNonNull(newView);
log.debug("Processing view update {}...", newView);
Map<JgroupsViewListener, Address[][]> diffs = new HashMap<>();
synchronized (viewListeners) {
viewListeners.forEach((viewListener, currentView) -> {
Address[][] diff = View.diff(currentView, newView);
viewListeners.put(viewListener, newView);
diffs.put(viewListener, diff);
});
}
diffs.forEach((viewListener, diff) -> {
for (Address joined : diff[0]) {
viewListener.memberJoined(joined);
}
for (Address left : diff[1]) {
viewListener.memberLeft(left);
}
});
}
示例3: handleView
import org.jgroups.View; //导入依赖的package包/类
protected void handleView(View new_view, View old_view, boolean coord_changed) {
if(is_coord) {
if(clear_table_on_view_change)
clearTable();
else if(old_view != null && new_view != null) {
Address[][] diff=View.diff(old_view, new_view);
Address[] left_mbrs=diff[1];
for(Address left_mbr : left_mbrs)
if(left_mbr != null && !new_view.containsMember(left_mbr))
remove(left_mbr);
}
}
if(coord_changed || clear_table_on_view_change)
writeOwnInformation(); // write immediately
if(info_writer_max_writes_after_view > 0)
startInfoWriter(); // and / or write in the background
}
示例4: installView
import org.jgroups.View; //导入依赖的package包/类
@Override
public void installView(NetView v) {
this.view = v;
if (this.jgAddress.getVmViewId() < 0) {
this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
}
List<JGAddress> mbrs = new ArrayList<>(v.size());
mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
View jgv = new View(vid, new ArrayList<>(mbrs));
logger.trace("installing JGroups view: {}", jgv);
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
addressesWithIoExceptionsProcessed.clear();
if (encrypt != null) {
encrypt.installView(v);
}
}
示例5: viewAccepted
import org.jgroups.View; //导入依赖的package包/类
@Override
public void viewAccepted(View view) {
if (endpoint.isEnableViewMessages()) {
Exchange exchange = endpoint.createExchange(view);
try {
LOG.debug("Processing view: {}", view);
processor.process(exchange, new AsyncCallback() {
@Override
public void done(boolean doneSync) {
// noop
}
});
} catch (Exception e) {
throw new JGroupsException("Error in consumer while dispatching exchange containing view " + view, e);
}
} else {
LOG.debug("Option enableViewMessages is set to false. Skipping processing of the view: {}", view);
}
}
示例6: dropNonCoordinatorViews
import org.jgroups.View; //导入依赖的package包/类
/**
* Creates predicate rejecting messages that are instances of {@code org.jgroups.View}, but have not been received
* by the coordinator JGroups node. This filter is useful for keeping only view messages indicating that receiving
* endpoint is a master node.
*
* @return predicate filtering out non-coordinator view messages.
*/
public static Predicate dropNonCoordinatorViews() {
return new Predicate() {
@Override
public boolean matches(Exchange exchange) {
Object body = exchange.getIn().getBody();
LOG.debug("Filtering message {}.", body);
if (body instanceof View) {
View view = (View) body;
Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.",
channelAddress, coordinatorNodeAddress);
return channelAddress.equals(coordinatorNodeAddress);
}
LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
return false;
}
};
}
示例7: start
import org.jgroups.View; //导入依赖的package包/类
public void start() throws Exception {
String props="udp.xml";
channel=new JChannel(props);
channel.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View view) {
setInternalState(view.getMembers());
}
public void setInternalState(java.util.List<Address> mbrs) {
members.clear();
for(Address mbr : mbrs)
addNode(mbr);
coordinator=mbrs.size() <= 1 || (mbrs.size() > 1 && mbrs.iterator().next().equals(my_addr));
repaint();
}
});
channel.connect(channel_name);
my_addr=channel.getAddress();
if(my_addr != null)
setTitle(my_addr.toString());
pack();
setVisible(true);
}
示例8: handleView
import org.jgroups.View; //导入依赖的package包/类
protected void handleView(View new_view, View old_view, boolean coord_changed) {
if(is_coord) {
if(clear_table_on_view_change)
clearTable();
else if(old_view != null && new_view != null) {
Address[][] diff=View.diff(old_view, new_view);
Address[] left_mbrs=diff[1];
for(Address left_mbr : left_mbrs)
if(left_mbr != null && !new_view.containsMember(left_mbr))
remove(cluster_name, left_mbr);
}
}
if(coord_changed || clear_table_on_view_change)
writeOwnInformation(true); // write immediately
if(info_writer_max_writes_after_view > 0)
startInfoWriter(); // and / or write in the background
}
示例9: readFrom
import org.jgroups.View; //导入依赖的package包/类
public void readFrom(DataInput in) throws Exception {
byte flags=in.readByte();
// 1. view
if((flags & VIEW_PRESENT) == VIEW_PRESENT) {
view=new View();
view.readFrom(in);
}
// 2. digest
if((flags & DIGEST_PRESENT) == DIGEST_PRESENT) {
digest=new Digest(view.getMembersRaw());
digest.readFrom(in, false);
}
// 3. fail_reason
if((flags & FAIL_REASON_PRESENT) == FAIL_REASON_PRESENT)
fail_reason=in.readUTF();
}
示例10: down
import org.jgroups.View; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object down(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
if(msg.isFlagSet(Message.Flag.NO_FC))
break;
int length=msg.getLength();
if(length == 0)
break;
return handleDownMessage(evt, msg, length);
case Event.CONFIG:
handleConfigEvent((Map<String,Object>)evt.getArg());
break;
case Event.VIEW_CHANGE:
handleViewChange(((View)evt.getArg()).getMembers());
break;
}
return down_prot.down(evt); // this could potentially use the lower protocol's thread which may block
}
示例11: down
import org.jgroups.View; //导入依赖的package包/类
public Object down(Event evt) {
switch(evt.getType()) {
case Event.SET_LOCAL_ADDRESS:
local_addr=(Address)evt.getArg();
break;
case Event.VIEW_CHANGE:
handleView((View)evt.getArg());
break;
}
if(num_event_handlers > 0) {
for(EventHandler handler: event_handlers) {
try {
handler.down(evt);
}
catch(Throwable t) {
log.error("event handler failed handling down event", t);
}
}
}
return down_prot.down(evt);
}
示例12: up
import org.jgroups.View; //导入依赖的package包/类
public Object up(Event evt) {
switch(evt.getType()) {
case Event.VIEW_CHANGE:
handleView((View)evt.getArg());
break;
}
if(num_event_handlers > 0) {
for(EventHandler handler: event_handlers) {
try {
handler.up(evt);
}
catch(Throwable t) {
log.error("event handler failed handling up event", t);
}
}
}
return up_prot.up(evt);
}
示例13: down
import org.jgroups.View; //导入依赖的package包/类
/**
* Fragment a packet if larger than frag_size (add a header). Otherwise just pass down. Only
* add a header if framentation is needed !
*/
public Object down(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
long size=msg.size();
num_sent_msgs++;
if(size > frag_size) {
if(log.isTraceEnabled()) {
StringBuilder sb=new StringBuilder("message size is ");
sb.append(size).append(", will fragment (frag_size=").append(frag_size).append(')');
log.trace(sb.toString());
}
fragment(msg, size); // Fragment and pass down
return null;
}
break;
case Event.VIEW_CHANGE:
handleViewChange((View)evt.getArg());
break;
}
return down_prot.down(evt); // Pass on to the layer below us
}
示例14: up
import org.jgroups.View; //导入依赖的package包/类
/**
* If event is a message, if it is fragmented, re-assemble fragments into big message and pass up the stack.
*/
public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
FragHeader hdr=(FragHeader)msg.getHeader(this.id);
if(hdr != null) { // needs to be defragmented
Message assembled_msg=unfragment(msg, hdr);
if(assembled_msg != null)
up_prot.up(new Event(Event.MSG, assembled_msg));
return null;
}
else {
num_received_msgs++;
}
break;
case Event.VIEW_CHANGE:
handleViewChange((View)evt.getArg());
break;
}
return up_prot.up(evt); // Pass up to the layer above us by default
}
示例15: down
import org.jgroups.View; //导入依赖的package包/类
/**
* Fragment a packet if larger than frag_size (add a header). Otherwise just pass down. Only
* add a header if fragmentation is needed !
*/
public Object down(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
long size=msg.getLength();
if(size > frag_size) {
fragment(msg); // Fragment and pass down
return null;
}
break;
case Event.VIEW_CHANGE:
handleViewChange((View)evt.getArg());
break;
case Event.SET_LOCAL_ADDRESS:
local_addr=(Address)evt.getArg();
break;
}
return down_prot.down(evt); // Pass on to the layer below us
}