Пример #1
0
 /**
  * is invoked in an implementation-specific fashion to determine if an instance is still valid
  * to be returned by the pool. It will only be invoked on an "activated" instance.
  *
  * @param an instance of {@link Session} maintained by this pool.
  * @return <code>true</code> if the connection is still alive and operative (checked by asking
  *     its user name), <code>false</code> otherwise.
  */
 @Override
 public boolean validateObject(Object obj) {
   ISession session = (ISession) obj;
   boolean valid = !session.isClosed();
   // MAKE PROPER VALIDITY CHECK HERE as for GEOT-1273
   if (valid) {
     try {
       if (LOGGER.isLoggable(Level.FINEST)) {
         LOGGER.finest("    Validating SDE Connection " + session);
       }
       /*
        * Validate the connection's health with testServer instead of getUser. The
        * former is lighter weight, getUser() forced a server round trip and under
        * heavy concurrency ate about 30% the time
        */
       session.testServer();
     } catch (IOException e) {
       LOGGER.info(
           "Can't validate SeConnection, discarding it: "
               + session
               + ". Reason: "
               + e.getMessage());
       valid = false;
     }
   }
   return valid;
 }
    @Override
    public void run() {
      /*
       * Do not retransmit a message if it has been acknowledged,
       * rejected, canceled or already been retransmitted for the maximum
       * number of times.
       */
      try {
        int failedCount = exchange.getFailedTransmissionCount() + 1;
        exchange.setFailedTransmissionCount(failedCount);

        if (message.isAcknowledged()) {
          LOGGER.finest(
              "Timeout: message already acknowledged, cancel retransmission of " + message);
          return;

        } else if (message.isRejected()) {
          LOGGER.finest("Timeout: message already rejected, cancel retransmission of " + message);
          return;

        } else if (message.isCanceled()) {
          LOGGER.finest("Timeout: canceled (MID=" + message.getMID() + "), do not retransmit");
          return;

        } else if (failedCount <= max_retransmit) {
          LOGGER.finer(
              "Timeout: retransmit message, failed: " + failedCount + ", message: " + message);

          // Trigger MessageObservers
          message.retransmitting();

          // MessageObserver might have canceled
          if (!message.isCanceled()) retransmit();

        } else {
          LOGGER.info(
              "Timeout: retransmission limit reached, exchange failed, message: " + message);
          exchange.setTimedOut();
          message.setTimedOut(true);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  @Override
  public boolean hasNext() {
    boolean exists = !isNextSourceFeatureNull();

    if (!isHasNextCalled()) {
      if (featureCounter < maxFeatures) {
        if (!exists && getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
          this.curSrcFeature = getSourceFeatureIterator().next();
          exists = true;
        }
        if (exists && filteredFeatures != null) {
          // get the next one if this row has already been added to the target
          // feature from setNextFilteredFeature
          while (exists && filteredFeatures.contains(extractIdForFeature(this.curSrcFeature))) {
            if (getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
              this.curSrcFeature = getSourceFeatureIterator().next();
              exists = true;
            } else {
              exists = false;
            }
          }
        }
        // HACK HACK HACK
        // evaluate filter that applies to this list as we want a subset
        // instead of full result
        // this is a temporary solution for Bureau of Meteorology
        // requirement for timePositionList
        if (listFilter != null) {
          while (exists && !listFilter.evaluate(curSrcFeature)) {
            // only add to subset if filter matches value
            if (getSourceFeatureIterator() != null && getSourceFeatureIterator().hasNext()) {
              this.curSrcFeature = getSourceFeatureIterator().next();
              exists = true;
            } else {
              exists = false;
            }
          }
        }
        // END OF HACK
      } else {
        exists = false;
      }
    }

    if (!exists) {
      LOGGER.finest("no more features, produced " + featureCounter);
      close();
      curSrcFeature = null;
    }

    setHasNextCalled(true);

    return exists;
  }
Пример #4
0
 @Override
 public void passivateObject(Object obj) {
   LOGGER.finest("    passivating connection " + obj);
   final Session conn = (Session) obj;
   conn.markInactive();
 }
Пример #5
0
    /*
     * The endpoint's executor executes this method to convert the raw bytes
     * into a message, look for an associated exchange and forward it to
     * the stack of layers.
     */
    private void receiveMessage(RawData raw) {
      DataParser parser = new DataParser(raw.getBytes());

      if (parser.isRequest()) {
        // This is a request
        Request request;
        try {
          request = parser.parseRequest();
        } catch (IllegalStateException e) {
          StringBuffer log =
              new StringBuffer("message format error caused by ")
                  .append(raw.getInetSocketAddress());
          if (!parser.isReply()) {
            // manually build RST from raw information
            EmptyMessage rst = new EmptyMessage(Type.RST);
            rst.setDestination(raw.getAddress());
            rst.setDestinationPort(raw.getPort());
            rst.setMID(parser.getMID());
            for (MessageInterceptor interceptor : interceptors) interceptor.sendEmptyMessage(rst);
            connector.send(serializer.serialize(rst));
            log.append(" and reset");
          }
          if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info(log.toString());
          }
          return;
        }
        request.setSource(raw.getAddress());
        request.setSourcePort(raw.getPort());
        request.setSenderIdentity(raw.getSenderIdentity());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */

        for (MessageInterceptor interceptor : interceptors) interceptor.receiveRequest(request);

        // MessageInterceptor might have canceled
        if (!request.isCanceled()) {
          Exchange exchange = matcher.receiveRequest(request);
          if (exchange != null) {
            exchange.setEndpoint(CoAPEndpoint.this);
            coapstack.receiveRequest(exchange, request);
          }
        }

      } else if (parser.isResponse()) {
        // This is a response
        Response response = parser.parseResponse();
        response.setSource(raw.getAddress());
        response.setSourcePort(raw.getPort());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */

        for (MessageInterceptor interceptor : interceptors) interceptor.receiveResponse(response);

        // MessageInterceptor might have canceled
        if (!response.isCanceled()) {
          Exchange exchange = matcher.receiveResponse(response);
          if (exchange != null) {
            exchange.setEndpoint(CoAPEndpoint.this);
            response.setRTT(System.currentTimeMillis() - exchange.getTimestamp());
            coapstack.receiveResponse(exchange, response);
          } else if (response.getType() != Type.ACK) {
            LOGGER.fine("Rejecting unmatchable response from " + raw.getInetSocketAddress());
            reject(response);
          }
        }

      } else if (parser.isEmpty()) {
        // This is an empty message
        EmptyMessage message = parser.parseEmptyMessage();
        message.setSource(raw.getAddress());
        message.setSourcePort(raw.getPort());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */

        for (MessageInterceptor interceptor : interceptors)
          interceptor.receiveEmptyMessage(message);

        // MessageInterceptor might have canceled
        if (!message.isCanceled()) {
          // CoAP Ping
          if (message.getType() == Type.CON || message.getType() == Type.NON) {
            LOGGER.info("Responding to ping by " + raw.getInetSocketAddress());
            reject(message);
          } else {
            Exchange exchange = matcher.receiveEmptyMessage(message);
            if (exchange != null) {
              exchange.setEndpoint(CoAPEndpoint.this);
              coapstack.receiveEmptyMessage(exchange, message);
            }
          }
        }
      } else {
        LOGGER.finest("Silently ignoring non-CoAP message from " + raw.getInetSocketAddress());
      }
    }
Пример #6
0
  public void decode(BitStream in) throws AACException {
    final int start = in.getPosition(); // should be 0

    int type;
    Element prev = null;
    boolean content = true;
    if (!config.getProfile().isErrorResilientProfile()) {
      while (content && (type = in.readBits(3)) != ELEMENT_END) {
        switch (type) {
          case ELEMENT_SCE:
          case ELEMENT_LFE:
            LOGGER.finest("SCE");
            prev = decodeSCE_LFE(in);
            break;
          case ELEMENT_CPE:
            LOGGER.finest("CPE");
            prev = decodeCPE(in);
            break;
          case ELEMENT_CCE:
            LOGGER.finest("CCE");
            decodeCCE(in);
            prev = null;
            break;
          case ELEMENT_DSE:
            LOGGER.finest("DSE");
            decodeDSE(in);
            prev = null;
            break;
          case ELEMENT_PCE:
            LOGGER.finest("PCE");
            decodePCE(in);
            prev = null;
            break;
          case ELEMENT_FIL:
            LOGGER.finest("FIL");
            decodeFIL(in, prev);
            prev = null;
            break;
        }
      }
      LOGGER.finest("END");
      content = false;
      prev = null;
    } else {
      // error resilient raw data block
      switch (config.getChannelConfiguration()) {
        case CHANNEL_CONFIG_MONO:
          decodeSCE_LFE(in);
          break;
        case CHANNEL_CONFIG_STEREO:
          decodeCPE(in);
          break;
        case CHANNEL_CONFIG_STEREO_PLUS_CENTER:
          decodeSCE_LFE(in);
          decodeCPE(in);
          break;
        case CHANNEL_CONFIG_STEREO_PLUS_CENTER_PLUS_REAR_MONO:
          decodeSCE_LFE(in);
          decodeCPE(in);
          decodeSCE_LFE(in);
          break;
        case CHANNEL_CONFIG_FIVE:
          decodeSCE_LFE(in);
          decodeCPE(in);
          decodeCPE(in);
          break;
        case CHANNEL_CONFIG_FIVE_PLUS_ONE:
          decodeSCE_LFE(in);
          decodeCPE(in);
          decodeCPE(in);
          decodeSCE_LFE(in);
          break;
        case CHANNEL_CONFIG_SEVEN_PLUS_ONE:
          decodeSCE_LFE(in);
          decodeCPE(in);
          decodeCPE(in);
          decodeCPE(in);
          decodeSCE_LFE(in);
          break;
        default:
          throw new AACException(
              "unsupported channel configuration for error resilience: "
                  + config.getChannelConfiguration());
      }
    }
    in.byteAlign();

    bitsRead = in.getPosition() - start;
  }