當前位置: 首頁>>代碼示例>>Java>>正文


Java DatagramPacket.release方法代碼示例

本文整理匯總了Java中io.netty.channel.socket.DatagramPacket.release方法的典型用法代碼示例。如果您正苦於以下問題:Java DatagramPacket.release方法的具體用法?Java DatagramPacket.release怎麽用?Java DatagramPacket.release使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.channel.socket.DatagramPacket的用法示例。


在下文中一共展示了DatagramPacket.release方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: release

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
/**
 * 釋放所有內存
 */
private void release()
{
  for (DatagramPacket dp : this.inputs)
  {
    dp.release();
  }
  this.inputs.clear();
  for (KcpOnUdp ku : this.kcps.values())
  {
    if (!ku.isClosed())
    {
      ku.release();
    }
  }
  this.kcps.clear();
}
 
開發者ID:beykery,項目名稱:jkcp,代碼行數:20,代碼來源:KcpThread.java

示例2: channelRead

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    DatagramPacket datagramPacket = (DatagramPacket) msg;
    Packet packet = PacketDecoder.decodeFrame(datagramPacket);
    receiver.onReceive(packet, connection);
    datagramPacket.release();//最後一個使用方要釋放引用
}
 
開發者ID:mpusher,項目名稱:mpush,代碼行數:8,代碼來源:UDPChannelHandler.java

示例3: onReceive

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
/**
 * receive DatagramPacket
 *
 * @param dp
 */
private void onReceive(DatagramPacket dp)
{
  if (this.running)
  {
    InetSocketAddress sender = dp.sender();
    int hash = sender.hashCode();
    hash = hash < 0 ? -hash : hash;
    this.workers[hash % workers.length].input(dp);
  } else
  {
    dp.release();
  }
}
 
開發者ID:beykery,項目名稱:jkcp,代碼行數:19,代碼來源:KcpServer.java

示例4: onReceive

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
/**
 * 收到服務器消息
 *
 * @param dp
 */
private void onReceive(DatagramPacket dp)
{
    if (this.kcp != null && this.running)
    {
        this.kcp.input(dp.content());
        synchronized (this.waitLock)
        {
            this.waitLock.notify();
        }
    } else
    {
        dp.release();
    }
}
 
開發者ID:beykery,項目名稱:jkcp,代碼行數:20,代碼來源:KcpClient.java

示例5: input

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
/**
 * 收到輸入
 */
void input(DatagramPacket dp)
{
  if (this.running)
  {
    this.inputs.add(dp);
    synchronized (this.lock)
    {
      lock.notify();
    }
  } else
  {
    dp.release();
  }
}
 
開發者ID:beykery,項目名稱:jkcp,代碼行數:18,代碼來源:KcpThread.java

示例6: channelRead0

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
  packet.retain();
  final boolean succeeded = queue.offer(packet);
  if (succeeded) {
    gaugeMap.put(GAUGE_NUM_QUEUED_PACKETS, queuedPacketCount.incrementAndGet());
    gaugeMap.put(GAUGE_PACKET_QUEUE_SIZE, queue.size());
  } else {
    gaugeMap.put(GAUGE_NUM_DROPPED_PACKETS, droppedPacketCount.incrementAndGet());
    // allow Netty to collect the buffer
    packet.release();
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:14,代碼來源:PacketQueueUDPHandler.java

示例7: receivePacket

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
private boolean receivePacket() throws Exception {
    DatagramPacket datagramPacket = this.socket.readPacket();
    if (datagramPacket != null) {
        // Check this early
        try {
            String source = datagramPacket.sender().getHostString();
            currentSource = source; //in order to block address
            if (this.block.containsKey(source)) {
                return true;
            }

            if (this.ipSec.containsKey(source)) {
                this.ipSec.put(source, this.ipSec.get(source) + 1);
            } else {
                this.ipSec.put(source, 1);
            }

            ByteBuf byteBuf = datagramPacket.content();
            if (byteBuf.readableBytes() == 0) {
                // Exit early to process another packet
                return true;
            }
            byte[] buffer = new byte[byteBuf.readableBytes()];
            byteBuf.readBytes(buffer);
            int len = buffer.length;
            int port = datagramPacket.sender().getPort();

            this.receiveBytes += len;

            byte pid = buffer[0];

            if (pid == UNCONNECTED_PONG.ID) {
                return false;
            }

            Packet packet = this.getPacketFromPool(pid);
            if (packet != null) {
                packet.buffer = buffer;
                this.getSession(source, port).handlePacket(packet);
                return true;
            } else if (pid == UNCONNECTED_PING.ID) {
                packet = new UNCONNECTED_PING();
                packet.buffer = buffer;
                packet.decode();

                UNCONNECTED_PONG pk = new UNCONNECTED_PONG();
                pk.serverID = this.getID();
                pk.pingID = ((UNCONNECTED_PING) packet).pingID;
                pk.serverName = this.getName();
                this.sendPacket(pk, source, port);
            } else if (buffer.length != 0) {
                this.streamRAW(source, port, buffer);
                return true;
            } else {
                return false;
            }
        } finally {
            datagramPacket.release();
        }
    }

    return false;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:64,代碼來源:SessionManager.java

示例8: receivePacket

import io.netty.channel.socket.DatagramPacket; //導入方法依賴的package包/類
private boolean receivePacket() throws Exception {
    DatagramPacket datagramPacket = this.socket.readPacket();
    if (datagramPacket != null) {
        // Check this early
        String source = datagramPacket.sender().getHostString();
        currentSource = source; //in order to block address
        if (this.block.containsKey(source)) {
            datagramPacket.release();
            return true;
        }

        if (this.ipSec.containsKey(source)) {
            this.ipSec.put(source, this.ipSec.get(source) + 1);
        } else {
            this.ipSec.put(source, 1);
        }

        ByteBuf byteBuf = datagramPacket.content();
        byte[] buffer = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(buffer);
        datagramPacket.release();
        int len = buffer.length;
        int port = datagramPacket.sender().getPort();
        if (len > 0) {
            this.receiveBytes += len;

            byte pid = buffer[0];

            if (pid == UNCONNECTED_PONG.ID) {
                return false;
            }

            Packet packet = this.getPacketFromPool(pid);
            if (packet != null) {
                packet.buffer = buffer;
                this.getSession(source, port).handlePacket(packet);
                return true;
            } else if (pid == UNCONNECTED_PING.ID) {
                packet = new UNCONNECTED_PING();
                packet.buffer = buffer;
                packet.decode();

                UNCONNECTED_PONG pk = new UNCONNECTED_PONG();
                pk.serverID = this.getID();
                pk.pingID = ((UNCONNECTED_PING) packet).pingID;
                pk.serverName = this.getName();
                this.sendPacket(pk, source, port);
            } else if (buffer.length != 0) {
                this.streamRAW(source, port, buffer);
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    return false;
}
 
開發者ID:BukkitPE,項目名稱:BukkitPE,代碼行數:61,代碼來源:SessionManager.java


注:本文中的io.netty.channel.socket.DatagramPacket.release方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。