Example usage for io.netty.buffer ByteBuf writeLong

List of usage examples for io.netty.buffer ByteBuf writeLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeLong.

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

From source file:net.tridentsdk.server.data.PositionWritable.java

License:Apache License

@Override
public void write(ByteBuf buf) {
    buf.writeLong((long) ((int) this.loc.x() & 0x3FFFFFF) << 38 | (long) ((int) this.loc.y() & 0xFFF) << 26
            | (long) ((int) this.loc.z() & 0x3FFFFFF));
}

From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnPlayer.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    Position loc = this.player.position();
    UUID id = this.player.uniqueId();

    Codec.writeVarInt32(buf, this.entityId);

    buf.writeLong(id.getMostSignificantBits());
    buf.writeLong(id.getLeastSignificantBits());

    buf.writeInt((int) loc.x() * 32);
    buf.writeInt((int) loc.y() * 32);
    buf.writeInt((int) loc.z() * 32);

    buf.writeByte((int) (byte) loc.yaw());
    buf.writeByte((int) (byte) loc.pitch());

    buf.writeShort(player.heldItem().id());
    metadata.write(buf);/* w  w w  .  ja v  a 2  s. com*/
}

From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSpawnPosition.java

License:Apache License

@Override
public void encode(ByteBuf buf) {
    buf.writeLong((long) (((int) this.location.x() & 0x3FFFFFF) << 6 | ((int) this.location.y() & 0xFFF) << 26
            | (int) this.location.z() & 0x3FFFFFF));
}

From source file:org.aotorrent.common.protocol.tracker.UDPAnnounceRequest.java

License:Apache License

@Override
public ByteBuf toTransmit() {
    final ByteBuf buf = Unpooled.buffer(98, 98);
    buf.writeLong(connectionId);
    buf.writeInt(action);//w  w  w. j ava2  s . c o  m
    buf.writeInt(transactionId);
    buf.writeBytes(infoHash);
    buf.writeBytes(peerId);
    buf.writeLong(downloaded);
    buf.writeLong(left);
    buf.writeLong(uploaded);
    buf.writeInt(event);
    buf.writeInt(0);
    buf.writeInt(0); // key
    buf.writeInt(-1);
    buf.writeShort(port);
    return buf;
}

From source file:org.aotorrent.common.protocol.tracker.UDPConnectRequest.java

License:Apache License

@Override
public ByteBuf toTransmit() {
    final ByteBuf buf = Unpooled.buffer(16, 16);
    buf.writeLong(connectionId);
    buf.writeInt(action);//from   w  w  w . j a v  a 2 s  . c  o  m
    buf.writeInt(transactionId);
    return buf;
}

From source file:org.apache.activemq.artemis.core.message.impl.CoreMessage.java

License:Apache License

public void encodeHeadersAndProperties(final ByteBuf buffer) {
    checkProperties();//w w  w  .j av a2s  .  c o  m
    messageIDPosition = buffer.writerIndex();
    buffer.writeLong(messageID);
    SimpleString.writeNullableSimpleString(buffer, address);
    if (userID == null) {
        buffer.writeByte(DataConstants.NULL);
    } else {
        buffer.writeByte(DataConstants.NOT_NULL);
        buffer.writeBytes(userID.asBytes());
    }
    buffer.writeByte(type);
    buffer.writeBoolean(durable);
    buffer.writeLong(expiration);
    buffer.writeLong(timestamp);
    buffer.writeByte(priority);
    properties.encode(buffer);
}

From source file:org.apache.activemq.artemis.utils.ByteUtil.java

License:Apache License

public static byte[] longToBytes(long x) {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8);
    buffer.writeLong(x);
    return buffer.array();
}

From source file:org.apache.bookkeeper.benchmark.BenchBookie.java

License:Apache License

/**
 * @param args//  ww w .j av a  2s.  c  om
 * @throws InterruptedException
 */
public static void main(String[] args)
        throws InterruptedException, ParseException, IOException, BKException, KeeperException {
    Options options = new Options();
    options.addOption("host", true, "Hostname or IP of bookie to benchmark");
    options.addOption("port", true, "Port of bookie to benchmark (default 3181)");
    options.addOption("zookeeper", true, "Zookeeper ensemble, (default \"localhost:2181\")");
    options.addOption("size", true, "Size of message to send, in bytes (default 1024)");
    options.addOption("warmupCount", true, "Number of messages in warmup phase (default 999)");
    options.addOption("latencyCount", true, "Number of messages in latency phase (default 5000)");
    options.addOption("throughputCount", true, "Number of messages in throughput phase (default 50000)");
    options.addOption("help", false, "This message");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help") || !cmd.hasOption("host")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("BenchBookie <options>", options);
        System.exit(-1);
    }

    String addr = cmd.getOptionValue("host");
    int port = Integer.parseInt(cmd.getOptionValue("port", "3181"));
    int size = Integer.parseInt(cmd.getOptionValue("size", "1024"));
    String servers = cmd.getOptionValue("zookeeper", "localhost:2181");
    int warmUpCount = Integer.parseInt(cmd.getOptionValue("warmupCount", "999"));
    int latencyCount = Integer.parseInt(cmd.getOptionValue("latencyCount", "5000"));
    int throughputCount = Integer.parseInt(cmd.getOptionValue("throughputCount", "50000"));

    EventLoopGroup eventLoop;
    if (SystemUtils.IS_OS_LINUX) {
        try {
            eventLoop = new EpollEventLoopGroup();
        } catch (Throwable t) {
            LOG.warn("Could not use Netty Epoll event loop for benchmark {}", t.getMessage());
            eventLoop = new NioEventLoopGroup();
        }
    } else {
        eventLoop = new NioEventLoopGroup();
    }

    OrderedExecutor executor = OrderedExecutor.newBuilder().name("BenchBookieClientScheduler").numThreads(1)
            .build();
    ScheduledExecutorService scheduler = Executors
            .newSingleThreadScheduledExecutor(new DefaultThreadFactory("BookKeeperClientScheduler"));

    ClientConfiguration conf = new ClientConfiguration();
    BookieClient bc = new BookieClientImpl(conf, eventLoop, PooledByteBufAllocator.DEFAULT, executor, scheduler,
            NullStatsLogger.INSTANCE);
    LatencyCallback lc = new LatencyCallback();

    ThroughputCallback tc = new ThroughputCallback();

    long ledger = getValidLedgerId(servers);
    for (long entry = 0; entry < warmUpCount; entry++) {
        ByteBuf toSend = Unpooled.buffer(size);
        toSend.resetReaderIndex();
        toSend.resetWriterIndex();
        toSend.writeLong(ledger);
        toSend.writeLong(entry);
        toSend.writerIndex(toSend.capacity());
        bc.addEntry(new BookieSocketAddress(addr, port), ledger, new byte[20], entry, ByteBufList.get(toSend),
                tc, null, BookieProtocol.FLAG_NONE, false, WriteFlag.NONE);
    }
    LOG.info("Waiting for warmup");
    tc.waitFor(warmUpCount);

    ledger = getValidLedgerId(servers);
    LOG.info("Benchmarking latency");
    long startTime = System.nanoTime();
    for (long entry = 0; entry < latencyCount; entry++) {
        ByteBuf toSend = Unpooled.buffer(size);
        toSend.resetReaderIndex();
        toSend.resetWriterIndex();
        toSend.writeLong(ledger);
        toSend.writeLong(entry);
        toSend.writerIndex(toSend.capacity());
        lc.resetComplete();
        bc.addEntry(new BookieSocketAddress(addr, port), ledger, new byte[20], entry, ByteBufList.get(toSend),
                lc, null, BookieProtocol.FLAG_NONE, false, WriteFlag.NONE);
        lc.waitForComplete();
    }
    long endTime = System.nanoTime();
    LOG.info("Latency: " + (((double) (endTime - startTime)) / ((double) latencyCount)) / 1000000.0);

    ledger = getValidLedgerId(servers);
    LOG.info("Benchmarking throughput");
    startTime = System.currentTimeMillis();
    tc = new ThroughputCallback();
    for (long entry = 0; entry < throughputCount; entry++) {
        ByteBuf toSend = Unpooled.buffer(size);
        toSend.resetReaderIndex();
        toSend.resetWriterIndex();
        toSend.writeLong(ledger);
        toSend.writeLong(entry);
        toSend.writerIndex(toSend.capacity());
        bc.addEntry(new BookieSocketAddress(addr, port), ledger, new byte[20], entry, ByteBufList.get(toSend),
                tc, null, BookieProtocol.FLAG_NONE, false, WriteFlag.NONE);
    }
    tc.waitFor(throughputCount);
    endTime = System.currentTimeMillis();
    LOG.info("Throughput: " + ((long) throughputCount) * 1000 / (endTime - startTime));

    bc.close();
    scheduler.shutdown();
    eventLoop.shutdownGracefully();
    executor.shutdown();
}

From source file:org.apache.bookkeeper.bookie.Bookie.java

License:Apache License

private ByteBuf createExplicitLACEntry(long ledgerId, ByteBuf explicitLac) {
    ByteBuf bb = allocator.directBuffer(8 + 8 + 4 + explicitLac.capacity());
    bb.writeLong(ledgerId);
    bb.writeLong(METAENTRY_ID_LEDGER_EXPLICITLAC);
    bb.writeInt(explicitLac.capacity());
    bb.writeBytes(explicitLac);//from  w  w  w  . j ava 2  s.c  o  m
    return bb;
}

From source file:org.apache.bookkeeper.bookie.Bookie.java

License:Apache License

/**
 * @param args//from ww w . jav  a2s . c o  m
 * @throws IOException
 * @throws InterruptedException
 */
public static void main(String[] args) throws IOException, InterruptedException, BookieException {
    Bookie b = new Bookie(new ServerConfiguration());
    b.start();
    CounterCallback cb = new CounterCallback();
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) {
        ByteBuf buff = Unpooled.buffer(1024);
        buff.writeLong(1);
        buff.writeLong(i);
        cb.incCount();
        b.addEntry(buff, false /* ackBeforeSync */, cb, null, new byte[0]);
    }
    cb.waitZero();
    long end = System.currentTimeMillis();
    System.out.println("Took " + (end - start) + "ms");
}