Package redis.netty4

Examples of redis.netty4.Command


      baos.write("6\r\n".getBytes());
      baos.write("foobar\r\n".getBytes());
    }
    byte[] multiBulkReply = baos.toByteArray();
    long start = System.currentTimeMillis();
    RedisReplyDecoder redisDecoder = new RedisReplyDecoder(false);
    ByteBuf cb = Unpooled.wrappedBuffer(multiBulkReply);
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 100000; j++) {
        Reply receive = redisDecoder.receive(cb);
        cb.resetReaderIndex();
      }
      long end = System.currentTimeMillis();
      long diff = end - start;
      System.out.println(diff + " " + ((double)diff)/100000);
View Full Code Here


*/
public class ReplyTest {
  @Test
  public void testReadWrite() throws IOException {
    ByteBuf os;
    Reply receive;
    RedisReplyDecoder redisDecoder = new RedisReplyDecoder(false);
    {
      os = Unpooled.buffer();
      String message = "OK";
      new StatusReply(message).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof StatusReply);
      assertEquals(message, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      new ErrorReply(message).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof ErrorReply);
      assertEquals(message, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      new BulkReply(Unpooled.wrappedBuffer(message.getBytes())).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof BulkReply);
      assertEquals(message, ((ByteBuf)receive.data()).toString(Charsets.US_ASCII));
    }
    {
      os = Unpooled.buffer();
      long integer = 999;
      new IntegerReply(integer).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof IntegerReply);
      assertEquals(integer, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      long integer = 999;
      new MultiBulkReply(new Reply[] {
              new StatusReply(message),
              new ErrorReply(message),
              new MultiBulkReply(new Reply[] { new StatusReply(message)}),
              new BulkReply(Unpooled.wrappedBuffer(message.getBytes())),
              new IntegerReply(integer)}).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof MultiBulkReply);
      Reply[] data = (Reply[]) receive.data();
      assertEquals(message, data[0].data());
      assertEquals(message, data[1].data());
      assertTrue(data[2] instanceof MultiBulkReply);
      Reply[] data2 = (Reply[]) data[2].data();
      assertEquals(message, data2[0].data());
View Full Code Here

    long start = System.currentTimeMillis();
    RedisReplyDecoder redisDecoder = new RedisReplyDecoder(false);
    ByteBuf cb = Unpooled.wrappedBuffer(multiBulkReply);
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 100000; j++) {
        Reply receive = redisDecoder.receive(cb);
        cb.resetReaderIndex();
      }
      long end = System.currentTimeMillis();
      long diff = end - start;
      System.out.println(diff + " " + ((double)diff)/100000);
View Full Code Here

      if (b >= 'A' && b <= 'Z') {
        name[i] = (byte) (b + LOWER_DIFF);
      }
    }
    Wrapper wrapper = methods.get(new BytesKey(name));
    Reply reply;
    if (wrapper == null) {
      reply = new ErrorReply("unknown command '" + new String(name, Charsets.US_ASCII) + "'");
    } else {
      reply = wrapper.execute(msg);
    }
    if (reply == QUIT) {
      ctx.close();
    } else {
      if (msg.isInline()) {
        if (reply == null) {
          reply = new InlineReply(null);
        } else {
          reply = new InlineReply(reply.data());
        }
      }
      if (reply == null) {
        reply = NYI_REPLY;
      }
View Full Code Here

    Reply receive;
    RedisReplyDecoder redisDecoder = new RedisReplyDecoder(false);
    {
      os = Unpooled.buffer();
      String message = "OK";
      new StatusReply(message).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof StatusReply);
      assertEquals(message, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      new ErrorReply(message).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof ErrorReply);
      assertEquals(message, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      new BulkReply(Unpooled.wrappedBuffer(message.getBytes())).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof BulkReply);
      assertEquals(message, ((ByteBuf)receive.data()).toString(Charsets.US_ASCII));
    }
    {
      os = Unpooled.buffer();
      long integer = 999;
      new IntegerReply(integer).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof IntegerReply);
      assertEquals(integer, receive.data());
    }
    {
      os = Unpooled.buffer();
      String message = "OK";
      long integer = 999;
      new MultiBulkReply(new Reply[] {
              new StatusReply(message),
              new ErrorReply(message),
              new MultiBulkReply(new Reply[] { new StatusReply(message)}),
              new BulkReply(Unpooled.wrappedBuffer(message.getBytes())),
              new IntegerReply(integer)}).write(os);
      receive = redisDecoder.receive(os);
      assertTrue(receive instanceof MultiBulkReply);
      Reply[] data = (Reply[]) receive.data();
View Full Code Here

        boolean isOff = _hasTrueInput(off);
        boolean isOn = _hasTrueInput(on);

        if ((brightLevel >= 0) && (brightLevel <= 100)) {
            _transmit(new Command((_destination), x10.Command.BRIGHT,
                    brightLevel));
        }

        if ((dimLevel >= 0) && (dimLevel <= 100)) {
            _transmit(new Command((_destination), x10.Command.DIM, dimLevel));
        }

        if (isOn) {
            _transmit(new Command((_destination), x10.Command.ON));
        }

        if (isOff) {
            _transmit(new Command((_destination), x10.Command.OFF));
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready.
        if (_commandReady()) {
            Command command = _getCommand();
            receivedCommand.send(0, new StringToken(_commandToString(command)));
        } else {
            receivedCommand.send(0, _EMPTY_STRING);
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready
        if (_commandReady()) {
            Command sensedCommand = _getCommand();
            byte function = sensedCommand.getFunctionByte();
            byte functionOfInterest = Command.BRIGHT;
            String commandValue = command.stringValue();

            if (!commandValue.equals("BRIGHT")) {
                functionOfInterest = Command.DIM;
            }

            String sensedHouseCode = "" + sensedCommand.getHouseCode();
            int sensedUnitCode = sensedCommand.getUnitCode();

            String houseCodeValue = houseCode.stringValue();
            int unitCodeValue = ((IntToken) unitCode.getToken()).intValue();

            if (sensedHouseCode.equals(houseCodeValue)
                    && (sensedUnitCode == unitCodeValue)
                    && (function == functionOfInterest)) {
                level.send(0, new IntToken(sensedCommand.getLevel()));
            } else {
                level.send(0, _NO_COMMAND_TOKEN);
            }
        } else {
            level.send(0, _NO_COMMAND_TOKEN);
View Full Code Here

        boolean isOn = _hasTrueInput(on);
        boolean isOff = _hasTrueInput(off);

        if (isOn) {
            _transmit(new Command((_destination), x10.Command.ON));
        }

        if (isOff) {
            _transmit(new Command((_destination), x10.Command.OFF));
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        // Check whether a command is ready
        if (_commandReady()) {
            Command sensedCommand = _getCommand();
            byte function = sensedCommand.getFunctionByte();
            byte functionOfInterest = Command.ON;
            String commandValue = command.stringValue();

            if (commandValue.equals("OFF")) {
                functionOfInterest = Command.OFF;
            } else if (commandValue.equals("ALL_LIGHTS_ON")) {
                functionOfInterest = Command.ALL_LIGHTS_ON;
            } else if (commandValue.equals("ALL_LIGHTS_OFF")) {
                functionOfInterest = Command.ALL_LIGHTS_OFF;
            } else if (commandValue.equals("ALL_UNITS_OFF")) {
                functionOfInterest = Command.ALL_UNITS_OFF;
            }

            String sensedHouseCode = "" + sensedCommand.getHouseCode();
            int sensedUnitCode = sensedCommand.getUnitCode();

            String houseCodeValue = houseCode.stringValue();
            int unitCodeValue = ((IntToken) unitCode.getToken()).intValue();

            if (sensedHouseCode.equals(houseCodeValue)
View Full Code Here

TOP

Related Classes of redis.netty4.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.