Package akka.util

Examples of akka.util.ByteString


        final Connected c2 = expectMsgClass(Connected.class);
        assert c1.localAddress().equals(c2.remoteAddress());
        assert c2.localAddress().equals(c1.remoteAddress());
       
        client.tell(ByteString.fromString("hello"), getRef());
        final ByteString reply = expectMsgClass(ByteString.class);
        assert reply.utf8String().equals("hello");
       
        watch(client);
        client.tell("close", getRef());
        expectTerminated(client);
      }
View Full Code Here


  //#simplistic-handler
  public class SimplisticHandler extends UntypedActor {
    @Override
    public void onReceive(Object msg) throws Exception {
      if (msg instanceof Received) {
        final ByteString data = ((Received) msg).data();
        System.out.println(data);
        getSender().tell(TcpMessage.write(data), getSelf());
      } else if (msg instanceof ConnectionClosed) {
        getContext().stop(getSelf());
      }
View Full Code Here

  }

  @Override
  public void onReceive(Object msg) throws Exception {
    if (msg instanceof Received) {
      final ByteString data = ((Received) msg).data();
      buffer(data);
      connection.tell(TcpMessage.write(data, ACK), getSelf());
      // now switch behavior to “waiting for acknowledgement”
      getContext().become(buffering, false);
View Full Code Here

      suspended = true;
    }
  }

  protected void acknowledge() {
    final ByteString acked = storage.remove();
    stored -= acked.size();
    transferred += acked.size();

    if (suspended && stored < lowWatermark) {
      log.debug("resuming reading");
      connection.tell(TcpMessage.resumeReading(), getSelf());
      suspended = false;
View Full Code Here

  protected void acknowledge(int ack) {
    assert ack == storageOffset;
    assert !storage.isEmpty();

    final ByteString acked = storage.remove();
    stored -= acked.size();
    transferred += acked.size();
    storageOffset += 1;

    if (suspended && stored < LOW_WATERMARK) {
      log.debug("resuming reading");
      connection.tell(TcpMessage.resumeReading(), getSelf());
View Full Code Here

        }

        @Override
        public void onReceive(Object message) throws Exception {
            if (message instanceof Tcp.Received) {
                ByteString data = ((Tcp.Received) message).data();
                connection.tell(TcpMessage.write(data, new Ack()), getSelf());
            } else if (message instanceof Ack) {
                connection.tell(TcpMessage.resumeReading(), getSelf());
            }
        }
View Full Code Here

      //#connected
      else
      //#received
      if (msg instanceof Tcp.Received) {
        final Tcp.Received recv = (Tcp.Received) msg;
        final ByteString data = recv.data();
        // and do something with the received data ...
      } else if (msg instanceof Tcp.CommandFailed) {
        final Tcp.CommandFailed failed = (Tcp.CommandFailed) msg;
        final Tcp.Command command = failed.cmd();
        // react to failed connect, bind, write, etc.
View Full Code Here

        //#connected
        else
          //#received
          if (msg instanceof UdpConnected.Received) {
            final UdpConnected.Received recv = (UdpConnected.Received) msg;
            final ByteString data = recv.data();
            // and do something with the received data ...
          } else if (msg instanceof UdpConnected.CommandFailed) {
            final UdpConnected.CommandFailed failed = (UdpConnected.CommandFailed) msg;
            final UdpConnected.Command command = failed.cmd();
            // react to failed connect, etc.
          } else if (msg instanceof UdpConnected.Disconnected) {
            // do something on disconnect
          }
          //#received
          else
          if ("send".equals(msg)) {
            ByteString data = ByteString.empty();
            //#send
            connectionActor.tell(UdpConnectedMessage.send(data), getSelf());
            //#send
          }
    }
View Full Code Here

      if (message.equals(TICK)) {
        MemoryUsage currentHeap = memory.getHeapMemoryUsage();
        long timestamp = System.currentTimeMillis();

        // use akka SerializationExtension to convert to bytes
        ByteString heapTopic = ByteString.fromString("health.heap", "UTF-8");
        ByteString heapPayload = ByteString.fromArray(
                ser.serialize(
                    new Heap(timestamp,
                          currentHeap.getUsed(),
                          currentHeap.getMax())
                ).get());
        // the first frame is the topic, second is the message
        pubSocket.tell(ZMQMessage.withFrames(heapTopic, heapPayload), getSelf());

        // use akka SerializationExtension to convert to bytes
        ByteString loadTopic = ByteString.fromString("health.load", "UTF-8");
        ByteString loadPayload = ByteString.fromArray(
                ser.serialize(new Load(timestamp, os.getSystemLoadAverage())).get()
        );
        // the first frame is the topic, second is the message
        pubSocket.tell(ZMQMessage.withFrames(loadTopic, loadPayload), getSelf());
      } else {
View Full Code Here

   public void onReceive(Object msg) throws Exception {
      if (msg instanceof Received) {
        
         switch (this.state) {
         case STARTED:
            ByteString in = ((Received) msg).data();
            provider = factory.getMessageProvider(in.toArray());

            builder = new org.flowforwarding.warp.protocol.ofp.avro.OFMessage.OFMessageBuilder(in.toArray());           
            OFMessage inMsg = builder.value(in.toArray()).build();

            if ((provider != null) && (inMsg != null)) {
                if (inMsg.type().equals("OFPT_HELLO")) {
                  log.info ("IN: Hello");
                    swRef.setVersion(builder.version());
//                    getSender().tell(TcpMessage.write(ByteString.fromArray(builder.type("ofp_hello").set("header.xid", "0xabba").build().binary())), getSelf());
                    OFMessage helloMsg = builder.type("ofp_hello").build();
                    byte[] v = {127,127,127,127};
                    helloMsg.get("header").get("xid").set(v);

                    //getSender().tell(TcpMessage.write(ByteString.fromArray(builder.type("ofp_hello").build().binary())), getSelf());
                    getSender().tell(TcpMessage.write(ByteString.fromArray(helloMsg.binary())), getSelf());
                    this.state = State.CONNECTED;
                    log.info ("STATE: Connected to OF Switch version "+ builder.version());
//                    getSender().tell(TcpMessage.write(ByteString.fromArray(builder.type("ofp_switch_features_request").set("xid", "0xabba").build().binary())), getSelf());
                    getSender().tell(TcpMessage.write(ByteString.fromArray(builder.type("ofp_switch_features_request").build().binary())), getSelf());

                    // TODO REMOVE THIS:
                    provider.init();
                    tcpChannel = getSender();
                }
            }
           
            break;
         case CONNECTED:  
            in = ((Received) msg).data();
            inMsg = builder.value(in.toArray()).build();
          
            if (inMsg.type().equals("OFPT_FEATURES_REPLY")) {
               log.info("IN: Features Reply");
               byte[] DPID = inMsg.field("datapath_id");
               swRef.setDpid(Convert.toLong(DPID));
               log.info("INFO: Switch DPID is " + Long.toHexString(Convert.toLong(DPID)).toUpperCase());
            
               state = State.HANDSHAKED;
               ofSessionHandler.tell(new OFEventHandshaked(swRef), getSelf());

               getSender().tell(TcpMessage.write(ByteString.fromArray(builder.type("ofp_get_config_request").build().binary())), getSelf());
            }
           
            break;
           
         case HANDSHAKED:
            in = ((Received) msg).data();
            inMsg = builder.value(in.toArray()).build();
           
            if (inMsg.type().equals("OFPT_GET_CONFIG_REPLY")) {
               log.info("IN: Config Reply from Switch " + Long.toHexString(swRef.getDpid().longValue()));
              
               OFMessage flowMod = builder.type("ofp_flow_mod").build();
/*               OFItemRef matchInPort = itemBuilder.type("oxm_tlv_ingress_port").build();
               matchInPort.set("tlv", "4");
               OFItemRef tlv = itemBuilder.type("oxm_tlv").build();
               tlv.add("match", matchInPort);
              
               OFMessageRef tlv_fields = builder.type("oxm_tlv_fields").build();
               //tlv_fields.add("oxm_tlvs", tlv);
               tlv_fields.get("oxm_tlvs").add(tlv);
              
               tlv_fields.binary();*/
            }
           
            if (provider.isConfig(in.toArray())) {
               ofSessionHandler.tell(new OFEventSwitchConfig(swRef, provider.parseSwitchConfig(in.toArray())), getSelf());
            } else if (provider.isPacketIn(in.toArray())) {
               System.out.println("[OF-INFO] DPID: " + Long.toHexString(swRef.getDpid().longValue()) +" Packet-In is received from the Switch");
               ofSessionHandler.tell(new OFEventPacketIn(swRef, provider.parsePacketIn(in.toArray())), getSelf());
            else if (provider.isError(in.toArray())) {
               System.out.println("[OF-INFO] DPID: " + Long.toHexString(swRef.getDpid().longValue()) + " Error is received from the Switch ");
               ofSessionHandler.tell(new OFEventError(swRef, provider.parseError(in.toArray())), getSelf());
            else if (provider.isEchoRequest(in.toArray())) {
               System.out.println("[OF-INFO] DPID: " + Long.toHexString(swRef.getDpid().longValue()) + " Echo request is received from the Switch ");
               getSender().tell(TcpMessage.write(ByteString.fromArray(provider.encodeEchoReply())), getSelf());
            }
            //ofSessionHandler.tell(new OFEventIncoming(swRef), getSelf());
           
View Full Code Here

TOP

Related Classes of akka.util.ByteString

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.