java类org.jboss.netty.channel.Channel的实例源码

GranitProtocolDecoder.java 文件源码 项目:traccar-service 阅读 22 收藏 0 点赞 0 评论 0
private static void sendResponseArchive(Channel channel, int deviceId, int packNum) {
    ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
    response.writeBytes("BB+ARCF~".getBytes(StandardCharsets.US_ASCII));
    response.writeShort(4); // length
    response.writeShort(packNum);
    response.writeShort(deviceId);
    appendChecksum(response, 14);
    channel.write(response);
}
TrakMateProtocolDecoder.java 文件源码 项目:traccar-service 阅读 31 收藏 0 点赞 0 评论 0
private Object decodeAlt(Channel channel, SocketAddress remoteAddress, String sentence) {

        Parser parser = new Parser(PATTERN_ALT, sentence);
        if (!parser.matches()) {
            return null;
        }

        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        if (deviceSession == null) {
            return null;
        }

        Position position = new Position();
        position.setProtocol(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());

        parser.next(); // seq
        position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt(0)));
        parser.next(); // alert status or data

        position.setLatitude(parser.nextDouble(0));
        position.setLongitude(parser.nextDouble(0));

        position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));

        position.setSpeed(parser.nextDouble(0));
        position.setCourse(parser.nextDouble(0));

        return position;
    }
HuaShengFrameDecoder.java 文件源码 项目:traccar-service 阅读 22 收藏 0 点赞 0 评论 0
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 2) {
        return null;
    }

    int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xC0);
    if (index != -1) {
        ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());

        while (buf.readerIndex() <= index) {
            int b = buf.readUnsignedByte();
            if (b == 0xDB) {
                int ext = buf.readUnsignedByte();
                if (ext == 0xDC) {
                    result.writeByte(0xC0);
                } else if (ext == 0xDD) {
                    result.writeByte(0xDB);
                }
            } else {
                result.writeByte(b);
            }
        }

        return result;
    }

    return null;
}
NettyTransport.java 文件源码 项目:Elasticsearch 阅读 37 收藏 0 点赞 0 评论 0
/**
 * Disconnects from a node, only if the relevant channel is found to be part of the node channels.
 */
protected boolean disconnectFromNode(DiscoveryNode node, Channel channel, String reason) {
    // this might be called multiple times from all the node channels, so do a lightweight
    // check outside of the lock
    NodeChannels nodeChannels = connectedNodes.get(node);
    if (nodeChannels != null && nodeChannels.hasChannel(channel)) {
        connectionLock.acquire(node.id());
        try {
            nodeChannels = connectedNodes.get(node);
            // check again within the connection lock, if its still applicable to remove it
            if (nodeChannels != null && nodeChannels.hasChannel(channel)) {
                connectedNodes.remove(node);
                try {
                    logger.debug("disconnecting from [{}], {}", node, reason);
                    nodeChannels.close();
                } finally {
                    logger.trace("disconnected from [{}], {}", node, reason);
                    transportServiceAdapter.raiseNodeDisconnected(node);
                }
                return true;
            }
        } finally {
            connectionLock.release(node.id());
        }
    }
    return false;
}
NettyTransport.java 文件源码 项目:Elasticsearch 阅读 27 收藏 0 点赞 0 评论 0
public void start() {
    List<Channel> newAllChannels = new ArrayList<>();
    newAllChannels.addAll(Arrays.asList(recovery));
    newAllChannels.addAll(Arrays.asList(bulk));
    newAllChannels.addAll(Arrays.asList(reg));
    newAllChannels.addAll(Arrays.asList(state));
    newAllChannels.addAll(Arrays.asList(ping));
    this.allChannels = Collections.unmodifiableList(newAllChannels);
}
NettyTransport.java 文件源码 项目:Elasticsearch 阅读 29 收藏 0 点赞 0 评论 0
public NodeChannels(Channel[] recovery, Channel[] bulk, Channel[] reg, Channel[] state, Channel[] ping) {
    this.recovery = recovery;
    this.bulk = bulk;
    this.reg = reg;
    this.state = state;
    this.ping = ping;
}
DefaultIsisInterface.java 文件源码 项目:athena 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Starts the hello timer which sends hello packet every configured seconds.
 *
 * @param channel netty channel instance
 */
public void startHelloSender(Channel channel) {
    log.debug("IsisInterfaceImpl::startHelloSender");
    if (!helloSenderStarted) {
        isisHelloPduSender = new IsisHelloPduSender(channel, this);
        exServiceHello = Executors.newSingleThreadScheduledExecutor();
        final ScheduledFuture<?> helloHandle =
                exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0,
                                                   helloInterval, TimeUnit.SECONDS);
        helloSenderStarted = true;
    }
}
H02ProtocolDecoder.java 文件源码 项目:traccar-service 阅读 23 收藏 0 点赞 0 评论 0
private Position decodeLink(String sentence, Channel channel, SocketAddress remoteAddress) {

        Parser parser = new Parser(PATTERN_LINK, sentence);
        if (!parser.matches()) {
            return null;
        }

        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        if (deviceSession == null) {
            return null;
        }

        Position position = new Position();
        position.setProtocol(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());

        DateBuilder dateBuilder = new DateBuilder()
                .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));

        position.set(Position.KEY_RSSI, parser.nextInt());
        position.set(Position.KEY_SATELLITES, parser.nextInt());
        position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
        position.set(Position.KEY_STEPS, parser.nextInt());
        position.set("turnovers", parser.nextInt());

        dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));

        getLastLocation(position, dateBuilder.getDate());

        processStatus(position, parser.nextLong(16, 0));

        return position;
    }
TeltonikaProtocolDecoder.java 文件源码 项目:traccar-service 阅读 24 收藏 0 点赞 0 评论 0
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;

    if (connectionless) {
        return decodeUdp(channel, remoteAddress, buf);
    } else {
        return decodeTcp(channel, remoteAddress, buf);
    }
}
H02ProtocolDecoder.java 文件源码 项目:traccar-service 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;
    String marker = buf.toString(0, 1, StandardCharsets.US_ASCII);

    switch (marker) {
        case "*":
            String sentence = buf.toString(StandardCharsets.US_ASCII);
            int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1;
            int typeEnd = sentence.indexOf(',', typeStart);
            if (typeEnd > 0) {
                String type = sentence.substring(typeStart, typeEnd);
                switch (type) {
                    case "NBR":
                        return decodeLbs(sentence, channel, remoteAddress);
                    case "LINK":
                        return decodeLink(sentence, channel, remoteAddress);
                    case "V3":
                        return decodeV3(sentence, channel, remoteAddress);
                    default:
                        return decodeText(sentence, channel, remoteAddress);
                }
            } else {
                return null;
            }
        case "$":
            return decodeBinary(buf, channel, remoteAddress);
        case "X":
        default:
            return null;
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号