@Override
 public byte[] serialize() {
   byte data[] = new byte[SIZE];
   ByteBuffer bb = ByteBuffer.wrap(data);
   bb.order(ByteOrder.BIG_ENDIAN);
   bb.putLong(fViewerSessionId);
   bb.putInt(fMajor);
   bb.putInt(fMinor);
   bb.putInt(fType.getCommand());
   return data;
 }
    @Override
    public ConnectionType getConnectionType() {
      String type = null;

      if (port_props.get(PORT_TYPE_PROP_KEY) == null) {
        log.warning(
            getName() + ": connection type is null: " + port_props.get(PORT_KEY).toString());
      } else {
        type = port_props.get(PORT_TYPE_PROP_KEY).toString();
      }

      return ConnectionType.valueOf(type);
    }
Beispiel #3
0
  public static void invoke(Configeration config, String paramStr) {
    // Parameter given is as follows:
    // Directive port-to-alias [alias-port(s)]
    paramStr = paramStr.trim();
    // Aquire data...
    int portStrEnd = paramStr.indexOf(" ");
    int port = parseInt(paramStr.substring(0, portStrEnd));
    // Now get the aliaser ports.
    String[] aliasList = paramStr.substring(portStrEnd + 1).trim().split(" ");

    for (String aliasPort : aliasList) {
      int alias = parseInt(aliasPort);
      ConnectionType.addAlias(port, alias);
      config.listenPorts.add(alias);
    }
  }
  /**
   * Creates a dialog where the user can specify the location of the database,including the type of
   * network connection (if this is a networked client)and IP address and port number; or search and
   * select the database on a local drive if this is a standalone client.
   *
   * @param parent Defines the Component that is to be the parent of this dialog box. For
   *     information on how this is used, see <code>JOptionPane</code>
   * @param connectionMode Specifies the type of connection (standalone or networked)
   * @see JOptionPane
   */
  public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) {
    configOptions = (new ConfigOptions(connectionMode));
    configOptions.getObservable().addObserver(this);

    // load saved configuration
    SavedConfiguration config = SavedConfiguration.getSavedConfiguration();

    // the port and connection type are irrelevant in standalone mode
    if (connectionMode == ApplicationMode.STANDALONE_CLIENT) {
      validPort = true;
      validCnx = true;
      networkType = ConnectionType.DIRECT;
      location = config.getParameter(SavedConfiguration.DATABASE_LOCATION);
    } else {
      // there may not be a network connectivity type defined and, if
      // not, we do not set a default - force the user to make a choice
      // the at least for the first time they run this.
      String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE);
      if (tmp != null) {
        try {
          networkType = ConnectionType.valueOf(tmp);
          configOptions.setNetworkConnection(networkType);
          validCnx = true;
        } catch (IllegalArgumentException e) {
          log.warning("Unknown connection type: " + networkType);
        }
      }

      // there is always at least a default port number, so we don't have
      // to validate this.
      port = config.getParameter(SavedConfiguration.SERVER_PORT);
      configOptions.setPortNumberText(port);
      validPort = true;

      location = config.getParameter(SavedConfiguration.SERVER_ADDRESS);
    }

    // there may not be a default database location, so we had better
    // validate before using the returned value.
    if (location != null) {
      configOptions.setLocationFieldText(location);
      validDb = true;
    }

    options =
        new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);

    connectButton.setActionCommand(CONNECT);
    connectButton.addActionListener(this);

    boolean allValid = validDb && validPort && validCnx;
    connectButton.setEnabled(allValid);

    exitButton.setActionCommand(EXIT);
    exitButton.addActionListener(this);

    options.setOptions(new Object[] {connectButton, exitButton});

    dialog = options.createDialog(parent, TITLE);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(this);
    dialog.setVisible(true);
  }
 public void setConnectionType(String connectionType) {
   this.connectionType = ConnectionType.toConnectionType(connectionType).toString();
 }
  @Override
  public void setProperties(Map<String, Object> props) throws ConfigurationException {
    super.setProperties(props);
    if (props.get(MAX_INACTIVITY_TIME) != null) {
      maxInactivityTime = (Long) props.get(MAX_INACTIVITY_TIME) * SECOND;
    }
    if (props.get(WHITE_CHAR_ACK_PROP_KEY) != null) {
      white_char_ack = (Boolean) props.get(WHITE_CHAR_ACK_PROP_KEY);
    }
    if (props.get(XMPP_ACK_PROP_KEY) != null) {
      xmpp_ack = (Boolean) props.get(XMPP_ACK_PROP_KEY);
    }
    if (props.get(NET_BUFFER_PROP_KEY) != null) {
      net_buffer = (Integer) props.get(NET_BUFFER_PROP_KEY);
    }
    if (props.get(NET_BUFFER_LIMIT_PROP_KEY) != null) {
      net_buffer_limit = (Integer) props.get(NET_BUFFER_LIMIT_PROP_KEY);
    }
    if (props.get(TRAFFIC_THROTTLING_PROP_KEY) != null) {
      String[] tmp = ((String) props.get(TRAFFIC_THROTTLING_PROP_KEY)).split(",");

      for (String tmp_s : tmp) {
        String[] tmp_thr = tmp_s.split(":");

        if (tmp_thr[0].equalsIgnoreCase("xmpp")) {
          last_minute_packets_limit =
              DataTypes.parseNum(tmp_thr[1], Long.class, LAST_MINUTE_PACKETS_LIMIT_PROP_VAL);
          log.warning(getName() + " last_minute_packets_limit = " + last_minute_packets_limit);
          total_packets_limit =
              DataTypes.parseNum(tmp_thr[2], Long.class, TOTAL_PACKETS_LIMIT_PROP_VAL);
          log.warning(getName() + " total_packets_limit = " + total_packets_limit);
          if (tmp_thr[3].equalsIgnoreCase("disc")) {
            xmppLimitAction = LIMIT_ACTION.DISCONNECT;
          }
          if (tmp_thr[3].equalsIgnoreCase("drop")) {
            xmppLimitAction = LIMIT_ACTION.DROP_PACKETS;
          }
        }
        if (tmp_thr[0].equalsIgnoreCase("bin")) {
          last_minute_bin_limit =
              DataTypes.parseNum(tmp_thr[1], Long.class, LAST_MINUTE_BIN_LIMIT_PROP_VAL);
          log.warning(getName() + " last_minute_bin_limit = " + last_minute_bin_limit);
          total_bin_limit = DataTypes.parseNum(tmp_thr[2], Long.class, TOTAL_BIN_LIMIT_PROP_VAL);
          log.warning(getName() + " total_bin_limit = " + total_bin_limit);
        }
      }
    }

    if (props.get(ELEMENTS_NUMBER_LIMIT_PROP_KEY) != null) {
      elements_number_limit = (int) props.get(ELEMENTS_NUMBER_LIMIT_PROP_KEY);
    }

    if (props.get(WATCHDOG_DELAY) != null) {
      watchdogDelay = (long) props.get(WATCHDOG_DELAY);
    }
    if (props.get(WATCHDOG_TIMEOUT) != null) {
      watchdogTimeout = (long) props.get(WATCHDOG_TIMEOUT);
    }
    if (props.get(WATCHDOG_PING_TYPE_KEY) != null) {
      String value = String.valueOf(props.get(WATCHDOG_PING_TYPE_KEY));
      watchdogPingType = WATCHDOG_PING_TYPE.valueOf(value.toUpperCase());
    }

    if (props.size() == 1) {

      // If props.size() == 1, it means this is a single property update and
      // ConnectionManager does not support it yet.
      return;
    }
    if (isInitializationComplete()) {

      // Do we really need to do this again?
      // Looks like reconfiguration for the port is not working correctly anyway
      // so for now we do not want to do it.
      return;
    }
    releaseListeners();

    int[] ports = (int[]) props.get(PORTS_PROP_KEY);

    if (ports != null) {
      for (int i = 0; i < ports.length; i++) {
        Map<String, Object> port_props = new LinkedHashMap<String, Object>(20);

        for (Map.Entry<String, Object> entry : props.entrySet()) {
          if (entry.getKey().startsWith(PROP_KEY + ports[i])) {
            int idx = entry.getKey().lastIndexOf('/');
            String key = entry.getKey().substring(idx + 1);

            log.log(
                Level.CONFIG,
                "Adding port property key: {0}={1}",
                new Object[] {key, entry.getValue()});
            port_props.put(key, entry.getValue());
          } // end of if (entry.getKey().startsWith())
        } // end of for ()
        port_props.put(PORT_KEY, ports[i]);
        if (port_props.containsKey(PORT_TYPE_PROP_KEY)
            && !(port_props.get(PORT_TYPE_PROP_KEY) instanceof ConnectionType)) {
          Object val = port_props.get(PORT_TYPE_PROP_KEY);
          port_props.put(PORT_TYPE_PROP_KEY, ConnectionType.valueOf(val.toString()));
        }
        if (port_props.containsKey(PORT_SOCKET_PROP_KEY)
            && !(port_props.get(PORT_SOCKET_PROP_KEY) instanceof SocketType)) {
          Object val = port_props.get(PORT_SOCKET_PROP_KEY);
          port_props.put(PORT_SOCKET_PROP_KEY, SocketType.valueOf(val.toString()));
        }
        addWaitingTask(port_props);
        // reconnectService(port_props, startDelay);
      } // end of for (int i = 0; i < ports.length; i++)
    } // end of if (ports != null)
  }
Beispiel #7
0
 public void setConnectionType(String allowConnections) {
   this.connectionType = ConnectionType.valueOf(allowConnections);
 }
  @Test
  public void testCheckConnectionTemplate() throws Exception {
    method =
        class1.getDeclaredMethod(
            "checkConnectionTemplate", new Class[] {AbstractConnection.class, Map.class});
    method.setAccessible(true);
    field = class1.getDeclaredField("getDefinitions");
    field.setAccessible(true);

    GetDefinitions getDefinitions = mock(GetDefinitions.class);
    AbstractConnection connection = mock(AbstractConnection.class);
    ConnectionDefinition connectionDefinition = mock(ConnectionDefinition.class);
    ConnectionType connectionType = mock(ConnectionType.class);
    PropertyDefinition propertyDefinition = mock(PropertyDefinition.class);
    PropertyName propertyName = mock(PropertyName.class);
    PropertyValues propertyValues = mock(PropertyValues.class);
    StringValue stringValue = mock(StringValue.class);
    PropertyDefinition.PropertyValueType type = PropertyDefinition.PropertyValueType.String;
    TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010
            .connection.instance.Property
        property =
            mock(
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object
                    .rev151010.connection.instance.Property.class);
    List<
            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010
                .connection.instance.Property>
        properties =
            new ArrayList<
                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object
                    .rev151010.connection.instance.Property>();
    List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
    List<StringValue> stringValues = new ArrayList<StringValue>();
    Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap =
        new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
    Map<ConnectionType, ConnectionDefinition> connDefinitions =
        new HashMap<ConnectionType, ConnectionDefinition>();

    field.set(updateTemplateDefinition, getDefinitions);
    propertyDefinitions.add(propertyDefinition);
    properties.add(property);
    stringValues.add(stringValue);
    parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType);

    when(getDefinitions.getConnectionDefinition()).thenReturn(connDefinitions);
    when(connection.getConnectionType()).thenReturn(connectionType);
    when(connectionType.getValue()).thenReturn("test");
    // test null
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, connection, parameterValueTypeMap)
            .equals(
                "The connection type "
                    + connection.getConnectionType().getValue()
                    + " is not defined."));
    // test not null
    connDefinitions.put(connectionType, connectionDefinition);
    when(connectionDefinition.getPropertyDefinition()).thenReturn(propertyDefinitions);
    when(propertyDefinition.getPropertyName()).thenReturn(propertyName);
    when(connection.getProperty()).thenReturn(null).thenReturn(properties);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null);
    when(property.getPropertyName()).thenReturn(mock(PropertyName.class)).thenReturn(propertyName);
    when(propertyName.getValue()).thenReturn("test");
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, connection, parameterValueTypeMap)
            .equals(
                "The property name " + property.getPropertyName().getValue() + " is not defined."));
    Assert.assertTrue(type.getIntValue() == 0);
    when(propertyDefinition.getPropertyValueType())
        .thenReturn(PropertyDefinition.PropertyValueType.Int)
        .thenReturn(type);
    Assert.assertTrue(
        method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null);
    verify(propertyDefinition).getPropertyValueType();
    when(property.getPropertyValues()).thenReturn(propertyValues);
    when(propertyValues.getStringValue()).thenReturn(stringValues);
    when(stringValue.getValue()).thenReturn(new String("ParameterName"));
    Assert.assertTrue(parameterValueTypeMap.get(new ParameterName("ParameterName")) == valueType);
    //        System.out.println((String) method.invoke(updateTemplateDefinition, connection,
    // parameterValueTypeMap));
    //        System.out.println("valuetype" + valueType.getIntValue());
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, connection, parameterValueTypeMap)
            .equals(
                "The property " + property.getPropertyName().getValue() + " type is not right."));
    verify(stringValue).getValue();
  }
Beispiel #9
0
 public void abortClientHandshake(String type) {
   FMLLog.log(Level.INFO, "Aborting client handshake \"%s\"", type);
   // FMLCommonHandler.instance().waitForPlayClient();
   completeClientSideConnection(ConnectionType.valueOf(type));
 }