/** @throws NullPointerException if the specified key is null */ public boolean remove(Object key, Object value) { Object val=get(key); boolean removed=val != null && value != null && val.equals(value); try { MethodCall call=new MethodCall(REMOVE_IF_EQUALS, key, value); disp.callRemoteMethods(null, call, call_options); } catch(Exception e) { throw new RuntimeException("remove(" + key + ", " + value + ") failed", e); } return removed; }
public void start(JChannel channel) throws Exception { map=new ReplicatedHashMap<>(channel); map.addNotifier(this); map.start(10000);
private void showAll() { if(listbox.getItemCount() > 0) listbox.removeAll(); if(map.isEmpty()) return; clearMsg(); String key; Float val; for(Map.Entry<String,Float> entry: map.entrySet()) { key=entry.getKey(); val=entry.getValue(); if(val == null) continue; listbox.add(key + ": " + val.toString()); } }
if (this.containerAddressesHashMap.size() == 0) { this.containerAddressesHashMap.put(this.containerConfiguration .getName(), this.discoveryCoordinationChannel .getLocalAddress()); } else if (this.containerAddressesHashMap.size() > new_view .getMembers().size()) { .keySet()) { if (!new_view.getMembers().contains( this.containerAddressesHashMap.get(containerName))) { this.containerAddressesHashMap.remove(containerName);
/** * Maps the specified key to the specified value in the hashtable. Neither of both parameters can be null * @param key - the hashtable key * @param value - the value * @return the previous value of the specified key in this hashtable, or null if it did not have one */ public V put(K key, V value) { V prev_val=get(key); if(send_message == true) { try { MethodCall call=new MethodCall((short)1, new Object[]{key, value}); disp.callRemoteMethods(null, call, update_mode, timeout); } catch(Exception e) { throw new RuntimeException("put(" + key + ", " + value + ") failed", e); } } else { _put(key, value); } return prev_val; }
/** * Removes the key (and its corresponding value) from the hashmap. * @param key - the key to be removed. * @return the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping. */ public V remove(Object key) { V retval=get(key); //Changes done by <aos> //if true, propagate action to the group if(send_message == true) { try { MethodCall call=new MethodCall((short)3, new Object[]{key}); disp.callRemoteMethods(null, call, update_mode, timeout); } catch(Exception e) { throw new RuntimeException("remove(" + key + ") failed", e); } } else { _remove(key); //don't have to do retval = super.remove(..) as is done at the beginning } return retval; }
/** * Initialize the JGROUPS channel and connect them to the group. * * @throws Exception */ private void startChannels() throws Exception { this.log.start(); // start the discovery HashMap and wait the synchronization of its data this.discoveryHashMapChannel.connect(this.domainConfiguration .getDomain()); this.containerAddressesHashMap.start(LATENTY_MAX_TIME); this.discoveryCoordinationChannel.connect(this.domainConfiguration .getDomain()); if (this.jndiHashMapChannel != null) { // start the JNDI HashMap and wait the synchronization of its data this.jndiHashMapChannel.connect(this.domainConfiguration .getDomain()); this.jndiHashMap.start(LATENTY_MAX_TIME); } this.log.end(); }
public void setState(InputStream istream) throws Exception { HashMap<K,V> new_copy=null; try(ObjectInputStream ois=new ObjectInputStream(istream)) { new_copy=(HashMap<K,V>)ois.readObject(); } if(new_copy != null) _putAll(new_copy); log.debug("state received successfully"); }
/** * Constructs a new ReplicatedHashMap with channel. Call {@link #start(long)} to start this map. */ public ReplicatedHashMap(JChannel channel) { this.channel=channel; this.map=new ConcurrentHashMap<>(); init(); }
public void getState(OutputStream ostream) throws Exception { HashMap<K,V> copy=new HashMap<>(); for(Map.Entry<K,V> entry:entrySet()) { K key=entry.getKey(); V val=entry.getValue(); copy.put(key, val); } try(ObjectOutputStream oos=new ObjectOutputStream(new BufferedOutputStream(ostream, 1024))) { oos.writeObject(copy); } }
.containsKey(newContainerConfiguration.getName())) { response = "Container named '" + newContainerConfiguration.getName() } else { this.containerAddressesHashMap.put( newContainerConfiguration.getName(), message .getSrc());
public void viewAccepted(View new_view) { List<Address> new_mbrs=new_view.getMembers(); if(new_mbrs != null) { sendViewChangeNotifications(new_view, new_mbrs, new ArrayList<>(members)); // notifies observers (joined, left) members.clear(); members.addAll(new_mbrs); } }
val=entry.getValue(); if(log.isTraceEnabled()) log.trace("inserting " + key + " --> " + val); put(key, val); // will replicate key and value
this.containerAddressesHashMap = new ReplicatedHashMap<String, Address>( this.discoveryHashMapChannel, LATENTY_MAX_TIME); this.jndiHashMap = new ReplicatedHashMap<String, HashMap<String, Object>>( this.jndiHashMapChannel, false, LATENTY_MAX_TIME); this.jndiHashMap.setBlockingUpdates(true);
private void removeItem() { int index=listbox.getSelectedIndex(); if(index == -1) { showMsg("No item selected in listbox to be deleted !"); return; } String s=listbox.getSelectedItem(); String key=s.substring(0, s.indexOf(':', 0)); if(key != null) map.remove(key); }
private void showAll() { if(listbox.getItemCount() > 0) listbox.removeAll(); if(map.isEmpty()) return; clearMsg(); String key; Float val; for(Map.Entry<String,Float> entry: map.entrySet()) { key=entry.getKey(); val=entry.getValue(); if(val == null) continue; listbox.add(key + ": " + val.toString()); } }
/** * Creates a ReplicatedHashMap * @param clustername The name of the group to join * @param factory The ChannelFactory which will be used to create a channel * @param properties The property string to be used to define the channel. This will override the properties of * the factory. If null, then the factory properties will be used * @param state_timeout The time to wait until state is retrieved in milliseconds. A value of 0 means wait forever. */ public ReplicatedHashMap(String clustername, ChannelFactory factory, String properties, long state_timeout) throws ChannelException { this.cluster_name=clustername; if(factory != null) { channel=properties != null? factory.createChannel(properties) : factory.createChannel(); } else { channel=new JChannel(properties); } disp=new RpcDispatcher(channel, this, this, this); disp.setMethodLookup(new MethodLookup() { public Method findMethod(short id) { return methods.get(id); } }); channel.connect(clustername); start(state_timeout); }
public void setState(InputStream istream) throws Exception { HashMap<K,V> new_copy=null; try(ObjectInputStream ois=new ObjectInputStream(istream)) { new_copy=(HashMap<K,V>)ois.readObject(); } if(new_copy != null) _putAll(new_copy); log.debug("state received successfully"); }
/** * Constructs a new ReplicatedHashMap using provided map instance. */ public ReplicatedHashMap(ConcurrentMap<K,V> map, JChannel channel) { if(channel == null) throw new IllegalArgumentException("Cannot create ReplicatedHashMap with null channel"); if(map == null) throw new IllegalArgumentException("Cannot create ReplicatedHashMap with null map"); this.map=map; this.cluster_name=channel.getClusterName(); this.channel=channel; init(); }