Examples of BinaryPacket


Examples of de.fu_berlin.inf.dpp.net.internal.BinaryPacketProto.BinaryPacket

                    throw new LocalCancellationException();

                if (inputStream == null)
                    throw new IOException("Socket already disposed");

                BinaryPacket packet = BinaryPacket
                    .parseDelimitedFrom(inputStream);
                if (packet == null) {
                    if (progress.isCanceled())
                        throw new LocalCancellationException();
                    throw new EOFException("No more packets");
                }

                final int objectid = packet.getObjectid();

                switch (packet.getType()) {
                case TRANSFERDESCRIPTION:
                    incomingDescriptionPackets.get(objectid).add(packet);

                    if (packet.getRemaining() == 0) {
                        List<BinaryPacket> list = incomingDescriptionPackets
                            .remove(objectid);

                        byte[] data = getData(list);

                        final TransferDescription transferDescription = buildTransferDescription(
                            objectid, data, progress);

                        // Side-effect! Create a new BlockingQueue in the
                        // incomingPackets AutoHashMap!
                        BlockingQueue<BinaryPacket> queue = incomingPackets
                            .get(objectid);
                        if (queue.size() > 0) {
                            log.warn("New incoming transfer, but already"
                                + " packets exist with the given ID!"
                                + " Discarding - " + transferDescription);
                            queue.clear();
                        }

                        return new BinaryChannelTransferObject(this,
                            transferDescription, objectid);
                    }
                    break;
                case DATA:
                    // Only keep packets for DATA we are expecting!
                    if (incomingPackets.containsKey(objectid))
                        incomingPackets.get(objectid).add(packet);
                    else {
                        if (log.isDebugEnabled())
                            log.warn("Discarding Packet: " + packet);
                    }
                    break;
                case CANCEL:
                    incomingDescriptionPackets.remove(objectid);
                    if (incomingPackets.containsKey(objectid)) {
                        // Pass the cancelation to the
                        // BinaryChanelTransferObject
                        // if no incomingPackets is found the transfer has
                        // already been finished
                        incomingPackets.get(objectid).add(packet);
                    }
                    break;
                case FINISHED: // fall through
                case REJECT:
                    remoteTransfers.get(objectid).add(packet);
                    break;
                case SHUTDOWN:
                    // TODO Terminate BinaryChannel
                    break;
                default:
                    log.error("Unknown BinaryHeaderType: " + packet.getType());
                }
            }

        } finally {
            progress.done();
View Full Code Here

Examples of de.fu_berlin.inf.dpp.net.internal.BinaryPacketProto.BinaryPacket

                throw new RemoteCancellationException();

            // send DATA
            sendDirect(PacketType.DATA, countData, objectid, data, progress);

            BinaryPacket confirmation = null;
            try {
                while (confirmation == null && isConnected()
                    && !progress.isCanceled()) {
                    confirmation = remoteTransfers.get(objectid).poll(500,
                        TimeUnit.MILLISECONDS);
                }
            } catch (InterruptedException e) {
                log.error("Code not designed to be interrupted", e);
                throw new CausedIOException(
                    "Binary Channel received unexpected exception while waiting for confirmation package",
                    e);
            }
            if (confirmation == null)
                throw new IOException(
                    "Binary Channel was closed while waiting for confirmation package");

            if (confirmation.getType() == PacketType.REJECT)
                throw new RemoteCancellationException();

            assert confirmation.getType() == PacketType.FINISHED;

        } catch (LocalCancellationException e) {

            log.debug("send was canceled:" + transferDescription.objectid);
View Full Code Here

Examples of de.fu_berlin.inf.dpp.net.internal.BinaryPacketProto.BinaryPacket

    public static BinaryPacket buildPacket(PacketType type, int objectid) {
        return buildPacket(type, 0, objectid, ByteString.EMPTY);
    }

    protected boolean isRejected(int objectid) {
        BinaryPacket packet = remoteTransfers.get(objectid).poll();
        if (packet != null) {
            return packet.getType() == PacketType.REJECT;
        }
        return false;
    }
View Full Code Here

Examples of de.fu_berlin.inf.dpp.net.internal.BinaryPacketProto.BinaryPacket

                    throw new LocalCancellationException(
                        "Data reception was manually cancelled.",
                        CancelOption.NOTIFY_PEER);
                }

                BinaryPacket packet;
                try {
                    packet = myPackets.poll(5, TimeUnit.SECONDS);
                    if (packet == null)
                        continue;

                } catch (InterruptedException e) {
                    log.error("Code not designed to be interrupted");
                    Thread.currentThread().interrupt();
                    return null;
                }

                if (packet.getType() == PacketType.CANCEL) {
                    assert packet.getObjectid() == objectid;

                    throw new RemoteCancellationException();
                }

                if (first) {
                    progress.beginTask(
                        "Receiving",
                        packet.getRemaining()
                            + (transferDescription
                                .compressInDataTransferManager() ? 1 : 0));
                    first = false;
                }

                resultList.add(packet);
                progress.worked(1);
                if (packet.getRemaining() == 0)
                    break;
            }

            this.binaryChannel.send(BinaryChannel.buildPacket(
                PacketType.FINISHED, objectid));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.