Search in sources :

Example 11 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class ClusterSplitLockTest method setUp.

@BeforeMethod
protected void setUp() throws Exception {
    for (int i = 0; i < MEMBERS; i++) {
        Protocol[] stack = Util.getTestStack(new CENTRAL_LOCK().level("debug").setValue("num_backups", 2));
        channels[i] = new JChannel(stack);
        lockServices[i] = new LockService(channels[i]);
        channels[i].setName(memberName(i));
        channels[i].connect("TEST");
        execs[i] = Executors.newCachedThreadPool();
        if (i == 0) {
            Util.sleep(500);
        }
    }
    Util.waitUntilAllChannelsHaveSameView(10000, 1000, channels);
    // Make sure A is coordinator, because we blindly assume it is in the tests below.
    assertTrue(channels[0].getView().getCoord().equals(channels[0].getAddress()));
}
Also used : JChannel(org.jgroups.JChannel) LockService(org.jgroups.blocks.locking.LockService) Protocol(org.jgroups.stack.Protocol) CENTRAL_LOCK(org.jgroups.protocols.CENTRAL_LOCK) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class PropertyHelper method getConvertedValue.

public static Object getConvertedValue(Object obj, Field field, String value, boolean check_scope) throws Exception {
    if (obj == null)
        throw new IllegalArgumentException("Cannot get converted value: Object is null");
    if (field == null)
        throw new IllegalArgumentException("Cannot get converted value: Field is null");
    Property annotation = field.getAnnotation(Property.class);
    if (annotation == null) {
        throw new IllegalArgumentException("Cannot get property name for field " + field.getName() + " which is not annotated with @Property");
    }
    String propertyName = field.getName();
    String name = obj instanceof Protocol ? ((Protocol) obj).getName() : obj.getClass().getName();
    PropertyConverter propertyConverter = (PropertyConverter) annotation.converter().newInstance();
    if (propertyConverter == null) {
        throw new Exception("Could not find property converter for field " + propertyName + " in " + name);
    }
    Object converted = null;
    try {
        String tmp = obj instanceof Protocol ? ((Protocol) obj).getName() + "." + propertyName : propertyName;
        converted = propertyConverter.convert(obj, field.getType(), tmp, value, check_scope);
    } catch (Exception e) {
        throw new Exception("Conversion of " + propertyName + " in " + name + " with original property value " + value + " failed", e);
    }
    return converted;
}
Also used : Protocol(org.jgroups.stack.Protocol) Property(org.jgroups.annotations.Property)

Example 13 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class JChannelProbeHandler method handleJmx.

protected void handleJmx(Map<String, String> map, String input) {
    Map<String, Object> tmp_stats;
    int index = input.indexOf('=');
    if (index > -1) {
        List<String> list = null;
        String protocol_name = input.substring(index + 1);
        index = protocol_name.indexOf('.');
        if (index > -1) {
            String rest = protocol_name;
            protocol_name = protocol_name.substring(0, index);
            // e.g. "num_sent,msgs,num_received_msgs"
            String attrs = rest.substring(index + 1);
            list = Util.parseStringList(attrs, ",");
            // check if there are any attribute-sets in the list
            for (Iterator<String> it = list.iterator(); it.hasNext(); ) {
                String tmp = it.next();
                index = tmp.indexOf('=');
                if (index != -1) {
                    String attrname = tmp.substring(0, index);
                    String attrvalue = tmp.substring(index + 1);
                    Object target = ch.getProtocolStack().findProtocol(protocol_name);
                    Field field = target != null ? Util.getField(target.getClass(), attrname) : null;
                    if (field == null && target instanceof AdditionalJmxObjects) {
                        Object[] objs = ((AdditionalJmxObjects) target).getJmxObjects();
                        if (objs != null && objs.length > 0) {
                            for (Object o : objs) {
                                field = o != null ? Util.getField(o.getClass(), attrname) : null;
                                if (field != null) {
                                    target = o;
                                    break;
                                }
                            }
                        }
                    }
                    if (field != null) {
                        Object value = Util.convert(attrvalue, field.getType());
                        if (value != null) {
                            if (target instanceof Protocol)
                                ((Protocol) target).setValue(attrname, value);
                            else
                                Util.setField(field, target, value);
                        }
                    } else {
                        // try to find a setter for X, e.g. x(type-of-x) or setX(type-of-x)
                        ResourceDMBean.Accessor setter = ResourceDMBean.findSetter(target, attrname);
                        if (setter == null && target instanceof AdditionalJmxObjects) {
                            Object[] objs = ((AdditionalJmxObjects) target).getJmxObjects();
                            if (objs != null && objs.length > 0) {
                                for (Object o : objs) {
                                    setter = o != null ? ResourceDMBean.findSetter(o, attrname) : null;
                                    if (setter != null)
                                        break;
                                }
                            }
                        }
                        if (setter != null) {
                            try {
                                Class<?> type = setter instanceof ResourceDMBean.FieldAccessor ? ((ResourceDMBean.FieldAccessor) setter).getField().getType() : setter instanceof ResourceDMBean.MethodAccessor ? ((ResourceDMBean.MethodAccessor) setter).getMethod().getParameterTypes()[0] : null;
                                Object converted_value = Util.convert(attrvalue, type);
                                setter.invoke(converted_value);
                            } catch (Exception e) {
                                log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e);
                            }
                        } else {
                            log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name);
                            setter = new ResourceDMBean.NoopAccessor();
                        }
                    }
                    it.remove();
                }
            }
        }
        tmp_stats = ch.dumpStats(protocol_name, list);
        if (tmp_stats != null) {
            for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
                Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
                String key = entry.getKey();
                map.put(key, tmp_map != null ? tmp_map.toString() : null);
            }
        }
    } else {
        tmp_stats = ch.dumpStats();
        if (tmp_stats != null) {
            for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
                Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
                String key = entry.getKey();
                map.put(key, tmp_map != null ? tmp_map.toString() : null);
            }
        }
    }
}
Also used : ResourceDMBean(org.jgroups.jmx.ResourceDMBean) Field(java.lang.reflect.Field) AdditionalJmxObjects(org.jgroups.jmx.AdditionalJmxObjects) Protocol(org.jgroups.stack.Protocol)

Example 14 with Protocol

use of org.jgroups.stack.Protocol in project fabric8 by jboss-fuse.

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    for (int i = 0; i < NUM; i++) {
        Protocol ping = createPing();
        channels[i] = new JChannel(new TCP(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS());
        channels[i].setName(Character.toString((char) ('A' + i)));
        channels[i].connect(CLUSTER_NAME);
        channels[i].setReceiver(receivers[i] = new MyReceiver());
    }
}
Also used : TCP(org.jgroups.protocols.TCP) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3) Before(org.junit.Before)

Example 15 with Protocol

use of org.jgroups.stack.Protocol in project wildfly by wildfly.

the class AbstractProtocolConfigurationServiceConfigurator method createProtocol.

@Override
public final P createProtocol(ProtocolStackConfiguration stackConfiguration) {
    String protocolName = this.name;
    String moduleName = this.moduleName;
    // A "native" protocol is one that is not specified as a class name
    boolean nativeProtocol = moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(Global.PREFIX);
    String className = nativeProtocol ? (Global.PREFIX + protocolName) : protocolName;
    try {
        Module module = this.loader.get().loadModule(moduleName);
        Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
        Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass));
        properties.putAll(this.properties);
        PrivilegedExceptionAction<Protocol> action = new PrivilegedExceptionAction<Protocol>() {

            @Override
            public Protocol run() throws Exception {
                try {
                    Protocol protocol = protocolClass.getConstructor().newInstance();
                    // These Configurator methods are destructive, so make a defensive copy
                    Map<String, String> copy = new HashMap<>(properties);
                    StackType type = Util.getIpStackType();
                    Configurator.resolveAndAssignFields(protocol, copy, type);
                    Configurator.resolveAndInvokePropertyMethods(protocol, copy, type);
                    List<Object> objects = protocol.getConfigurableObjects();
                    if (objects != null) {
                        for (Object object : objects) {
                            Configurator.resolveAndAssignFields(object, copy, type);
                            Configurator.resolveAndInvokePropertyMethods(object, copy, type);
                        }
                    }
                    if (!copy.isEmpty()) {
                        for (String property : copy.keySet()) {
                            JGroupsLogger.ROOT_LOGGER.unrecognizedProtocolProperty(protocolName, property);
                        }
                    }
                    return protocol;
                } catch (InstantiationException | IllegalAccessException e) {
                    throw new IllegalStateException(e);
                }
            }
        };
        @SuppressWarnings("unchecked") P protocol = (P) WildFlySecurityManager.doUnchecked(action);
        this.accept(protocol);
        protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled());
        return protocol;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : HashMap(java.util.HashMap) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) OperationFailedException(org.jboss.as.controller.OperationFailedException) StackType(org.jgroups.util.StackType) Module(org.jboss.modules.Module) Protocol(org.jgroups.stack.Protocol)

Aggregations

Protocol (org.jgroups.stack.Protocol)87 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)18 JChannel (org.jgroups.JChannel)17 GMS (org.jgroups.protocols.pbcast.GMS)17 STABLE (org.jgroups.protocols.pbcast.STABLE)13 ProtocolStack (org.jgroups.stack.ProtocolStack)12 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Property (org.jgroups.annotations.Property)6 HashMap (java.util.HashMap)5 ForkProtocol (org.jgroups.fork.ForkProtocol)5 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)5 InetAddress (java.net.InetAddress)4 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 Message (org.jgroups.Message)3 FORK (org.jgroups.protocols.FORK)3 UNICAST3 (org.jgroups.protocols.UNICAST3)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Method (java.lang.reflect.Method)2