Example usage for io.netty.util Attribute remove

List of usage examples for io.netty.util Attribute remove

Introduction

In this page you can find the example usage for io.netty.util Attribute remove.

Prototype

@Deprecated
void remove();

Source Link

Document

Removes this attribute from the AttributeMap .

Usage

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testGetSetString() {
    AttributeKey<String> key = AttributeKey.valueOf("Nothing");
    Attribute<String> one = map.attr(key);

    assertSame(one, map.attr(key));//from   w ww  .j  av  a  2  s.  c om

    one.setIfAbsent("Whoohoo");
    assertSame("Whoohoo", one.get());

    one.setIfAbsent("What");
    assertNotSame("What", one.get());

    one.remove();
    assertNull(one.get());
}

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testGetSetInt() {
    AttributeKey<Integer> key = AttributeKey.valueOf("Nada");
    Attribute<Integer> one = map.attr(key);

    assertSame(one, map.attr(key));//w  w  w .j  av a 2  s.c  o m

    one.setIfAbsent(3653);
    assertEquals(Integer.valueOf(3653), one.get());

    one.setIfAbsent(1);
    assertNotSame(1, one.get());

    one.remove();
    assertNull(one.get());
}

From source file:com.linecorp.armeria.internal.DefaultAttributeMapTest.java

License:Apache License

@Test
public void testIteratorWithFullMap() {
    final List<AttributeKey<Integer>> expectedKeys = new ArrayList<>();
    for (int i = 0; i < 1024; i++) {
        final AttributeKey<Integer> key = AttributeKey.valueOf(DefaultAttributeMapTest.class,
                String.valueOf(i));
        expectedKeys.add(key);//from w w  w  .  j  a  v  a 2s.c o m
        map.attr(key).set(i);
    }

    // Make sure all buckets are filled.
    for (int i = 0; i < map.attributes.length(); i++) {
        assertNotNull(map.attributes.get(i));
    }

    // Make sure the Iterator yields all attributes.
    assertEquals(expectedKeys, actualKeys());

    // Make sure the Iterator does not yield the attributes whose 'removed' property is 'true'.
    for (int i = 0; i < map.attributes.length(); i++) {
        Attribute<?> a = map.attributes.get(i);
        a.remove();

        // A head attribute is never removed from the linked list.
        assertSame(a, map.attributes.get(i));

        // Remove the removed key from the list of expected expectedKeys.
        expectedKeys.remove(a.key());
    }

    assertEquals(expectedKeys, actualKeys());
}

From source file:net.hasor.rsf.console.TelnetHandler.java

License:Apache License

private void clearAttr(ChannelHandlerContext ctx) {
    Attribute<RsfCommandSession> sessionAttr = ctx.attr(SessionKEY);
    Attribute<RsfCommandRequest> attr = ctx.attr(RequestKEY);
    if (sessionAttr != null) {
        logger.info("rsfConsole -> clearAttr ,remove sessionAttr.");
        sessionAttr.remove();
    }//www.  ja  va  2  s. co m
    if (attr != null) {
        logger.info("rsfConsole -> clearAttr ,remove requestAttr.");
        attr.remove();
    }
}

From source file:net.hasor.rsf.console.TelnetHandler.java

License:Apache License

private RsfCommandResponse doRequest(final Attribute<RsfCommandRequest> cmdAttr,
        final ChannelHandlerContext ctx, final String inputString) {
    // .//from   w  w w  .j  a v  a2  s . co  m
    logger.info("rsfConsole -> doRequest, pre environment.");
    RsfCommandRequest requestCmd = cmdAttr.get();
    Attribute<RsfCommandSession> sessionAttr = ctx.attr(SessionKEY);
    boolean newCommand = (requestCmd == null);
    //
    // .?
    if (requestCmd == null) {
        String requestCMD = inputString;
        String requestArgs = "";
        int cmdIndex = inputString.indexOf(" ");
        if (inputString.indexOf(" ") > 0) {
            requestCMD = inputString.substring(0, cmdIndex);
            requestArgs = inputString.substring(cmdIndex + 1);
        }
        RsfInstruct rsfInstruct = this.commandManager.findCommand(requestCMD);
        if (rsfInstruct == null) {
            String msgStr = "'" + requestCMD + "' is bad command.";
            logger.info("rsfConsole -> " + msgStr);
            return new RsfCommandResponse(msgStr, true, false);
        }
        //
        logger.info("rsfConsole -> doRequest, RsfCommandRequest in ctx exist. -> command = {} , args = {}",
                requestCMD, requestArgs);
        requestCmd = new RsfCommandRequest(requestCMD, sessionAttr.get(), rsfInstruct, requestArgs);
        cmdAttr.set(requestCmd);
    }
    //
    // .????
    if (requestCmd.inputMultiLine()) {
        /*?*/
        if (requestCmd.getStatus() == CommandRequestStatus.Prepare) {
            if (!newCommand) {
                requestCmd.appendRequestBody(inputString);
            }
            if (StringUtils.isBlank(inputString)) {
                requestCmd.inReady();//
            }
        } else if (requestCmd.getStatus() == CommandRequestStatus.Ready) {
            if (StringUtils.isBlank(inputString)) {
                requestCmd.inStandBy();//
            } else {
                requestCmd.appendRequestBody(inputString);
            }
        }
    } else {
        /*??*/
        requestCmd.inStandBy();
    }
    //
    //3.
    if (requestCmd.getStatus() == CommandRequestStatus.StandBy) {
        logger.info("rsfConsole -> doRequest, doRunning.");
        requestCmd.doCommand(executor, new Runnable() {
            public void run() {
                cmdAttr.remove();
                ctx.writeAndFlush("\r\n" + CMD);
            }
        });
        //?
        return requestCmd.getResponse();
    } else if (requestCmd.getStatus() == CommandRequestStatus.Running) {
        return new RsfCommandResponse("command is running, please wait a moment.", false, false);
    }
    //
    return null;
}

From source file:org.hawkular.metrics.clients.ptrans.MetricBatcher.java

License:Apache License

/**
 * Batch up incoming SingleMetric messages. If the #minimumBatchSize is not yet reached, the messages are stored
 * locally. Otherwise the list of messages will be forwarded to the next handler.
 * This method will be called for each written message that can be handled
 * by this encoder./*from w w  w  .j a v  a 2 s . c  o m*/
 *
 * @param ctx           the {@link ChannelHandlerContext} which this {@link MessageToMessageDecoder} belongs to
 * @param msg           the SingleMetric to be batched up
 * @param out           the {@link List} to which decoded messages should be added if the batch size is reached
 * @throws Exception    is thrown if an error occurs
 */
@Override
protected void decode(ChannelHandlerContext ctx, SingleMetric msg, List<Object> out) throws Exception {
    LOG.trace("Incoming metric for key '{}'", cacheKey.name());
    Attribute<List<SingleMetric>> cache = ctx.attr(cacheKey);
    List<SingleMetric> batchList = cache.get();
    if (batchList == null) {
        LOG.trace("Creating new batch list for key '{}'", cacheKey.name());
        batchList = new ArrayList<>(minimumBatchSize);
        cache.set(batchList);
    }
    batchList.add(msg);
    if (batchList.size() >= minimumBatchSize) {
        LOG.trace("Batch size limit '{}' reached for key '{}'", minimumBatchSize, cacheKey.name());
        cache.remove();
        out.add(batchList);
    }
}