Search in sources :

Example 11 with ManagedOperation

use of org.jgroups.annotations.ManagedOperation in project JGroups by belaban.

the class TCPGOSSIP method removeInitialHost.

@ManagedOperation
public boolean removeInitialHost(String hostname, int port) {
    InetSocketAddress isa = new InetSocketAddress(hostname, port);
    stubManager.unregisterStub(new IpAddress(isa.getAddress(), isa.getPort()));
    return initial_hosts.remove(isa);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 12 with ManagedOperation

use of org.jgroups.annotations.ManagedOperation in project JGroups by belaban.

the class Discovery method addToCache.

@ManagedOperation(description = "Reads logical-physical address mappings and logical name mappings from a " + "file (or URL) and adds them to the local caches")
public void addToCache(String filename) throws Exception {
    InputStream in = ConfiguratorFactory.getConfigStream(filename);
    List<PingData> list = read(in);
    if (list != null)
        for (PingData data : list) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
}
Also used : InputStream(java.io.InputStream) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 13 with ManagedOperation

use of org.jgroups.annotations.ManagedOperation in project JGroups by belaban.

the class INJECT_VIEW method injectView.

@ManagedOperation(description = "Inject a view (example of view string format: A=A/B/C;B=B/C;C=C)")
public synchronized void injectView(String newView) {
    try {
        log.info("[INJECT_VIEW] Received request to inject view %s\n", newView);
        String[] perNode = newView.split(NODE_VIEWS_SEPARATOR);
        String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString();
        for (String nodeView : perNode) {
            if (nodeView.startsWith(thisNodeAddress)) {
                log.info("[INJECT_VIEW] [channel: %s] Injecting a new view: %s\n", thisNodeAddress, nodeView);
                long viewId = getProtocolStack().getChannel().getView().getViewId().getId() + 1;
                List<Address> nodes = new ArrayList<>();
                for (String nodeName : nodeView.split(VIEW_SEPARATOR)[1].split(NAMES_SEPARATOR)) {
                    for (Map.Entry<Address, String> entry : NameCache.getContents().entrySet()) {
                        if (nodeName.equals(entry.getValue())) {
                            log.debug("[INJECT_VIEW] [channel: %s] Found name: <%s> for address: <%s>\n", entry.getValue(), entry.getKey().toString());
                            nodes.add(entry.getKey());
                            break;
                        }
                    }
                }
                View view = new View(nodes.get(0), viewId, nodes);
                GMS gms = getProtocolStack().findProtocol(GMS.class);
                gms.installView(view);
                log.info("[INJECT_VIEW] [channel: %s] Injection finished of view: %s\n", thisNodeAddress, nodeView);
            }
        }
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    }
}
Also used : Address(org.jgroups.Address) ArrayList(java.util.ArrayList) GMS(org.jgroups.protocols.pbcast.GMS) Map(java.util.Map) View(org.jgroups.View) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 14 with ManagedOperation

use of org.jgroups.annotations.ManagedOperation in project JGroups by belaban.

the class ReplCache method stop.

@ManagedOperation
public void stop() {
    if (l1_cache != null)
        l1_cache.stop();
    if (migrate_data) {
        List<Address> members_without_me = new ArrayList<>(view.getMembers());
        members_without_me.remove(local_addr);
        HashFunction<K> tmp_hash_function = hash_function_factory.create();
        tmp_hash_function.installNodes(members_without_me);
        for (Map.Entry<K, Cache.Value<Value<V>>> entry : l2_cache.entrySet()) {
            K key = entry.getKey();
            Cache.Value<Value<V>> val = entry.getValue();
            if (val == null)
                continue;
            Value<V> tmp = val.getValue();
            if (tmp == null)
                continue;
            short repl_count = tmp.getReplicationCount();
            if (// we only handle keys which are not replicated and which are stored by us
            repl_count != 1)
                continue;
            List<Address> nodes = tmp_hash_function.hash(key, repl_count);
            if (nodes == null || nodes.isEmpty())
                continue;
            if (!nodes.contains(local_addr)) {
                // should only have 1 element anyway
                Address dest = nodes.get(0);
                move(dest, key, tmp.getVal(), repl_count, val.getTimeout(), true);
                _remove(key);
            }
        }
    }
    l2_cache.removeChangeListener(this);
    l2_cache.stop();
    disp.stop();
    ch.close();
}
Also used : Address(org.jgroups.Address) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 15 with ManagedOperation

use of org.jgroups.annotations.ManagedOperation in project JGroups by belaban.

the class ReplCache method start.

@ManagedOperation
public void start() throws Exception {
    if (hash_function_factory != null) {
        hash_function = hash_function_factory.create();
    }
    if (hash_function == null)
        hash_function = new ConsistentHashFunction<>();
    ch = new JChannel(props);
    disp = new RpcDispatcher(ch, this).setMethodLookup(methods::get).setMembershipListener(this);
    Marshaller marshaller = new CustomMarshaller();
    disp.setMarshaller(marshaller);
    ch.connect(cluster_name);
    local_addr = ch.getAddress();
    view = ch.getView();
    timer = ch.getProtocolStack().getTransport().getTimer();
    l2_cache.addChangeListener(this);
}
Also used : JChannel(org.jgroups.JChannel) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Aggregations

ManagedOperation (org.jgroups.annotations.ManagedOperation)15 Address (org.jgroups.Address)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 IpAddress (org.jgroups.stack.IpAddress)3 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JChannel (org.jgroups.JChannel)2 PhysicalAddress (org.jgroups.PhysicalAddress)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 ServerSocket (java.net.ServerSocket)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 View (org.jgroups.View)1 ManagedAttribute (org.jgroups.annotations.ManagedAttribute)1 Property (org.jgroups.annotations.Property)1