// Path: action/src/main/java/io/cettia/asity/action/Actions.java
// public interface Actions<T> {
// 
//   /**
//    * Adds an action.
//    */
//   Actions<T> add(Action<T> action);
// 
//   /**
//    * Disables any operation on the actions. This method is useful when
//    * multiple events are mutually exclusive.
//    */
//   Actions<T> disable();
// 
//   /**
//    * Determines if the actions has been disabled.
//    */
//   boolean disabled();
// 
//   /**
//    * Removes all of the actions.
//    */
//   Actions<T> empty();
// 
//   /**
//    * Fire all of the actions.
//    */
//   Actions<T> fire();
// 
//   /**
//    * Fire all of the actions with the given value.
//    */
//   Actions<T> fire(T data);
// 
//   /**
//    * Determines if the actions have been called at least once.
//    */
//   boolean fired();
// 
//   /**
//    * Determines if the actions contains an action.
//    */
//   boolean has();
// 
//   /**
//    * Determines whether the actions contains the specified action.
//    */
//   boolean has(Action<T> action);
// 
//   /**
//    * Removes an action.
//    */
//   Actions<T> remove(Action<T> action);
// 
//   /**
//    * Options to create an Actions. With the default options, an Action will
//    * work like a typical event manager.
//    *
//    * @author Donghwan Kim
//    */
//   class Options {
// 
//     private boolean once;
//     private boolean memory;
//     private boolean unique;
// 
//     public Options() {
//     }
// 
//     public Options(Options options) {
//       once = options.once;
//       memory = options.memory;
//       unique = options.unique;
//     }
// 
//     public boolean once() {
//       return once;
//     }
// 
//     /**
//      * Ensures the actions can only be fired once. The default value is
//      * false.
//      */
//     public Options once(boolean once) {
//       this.once = once;
//       return this;
//     }
// 
//     public boolean memory() {
//       return memory;
//     }
// 
//     /**
//      * Keeps track of previous values and will call any action added after
//      * the actions has been fired right away with the latest "memorized"
//      * values. The default value is false.
//      */
//     public Options memory(boolean memory) {
//       this.memory = memory;
//       return this;
//     }
// 
//     public boolean unique() {
//       return unique;
//     }
// 
//     /**
//      * Ensures an action can only be added once. The default value is false.
//      */
//     public Options unique(boolean unique) {
//       this.unique = unique;
//       return this;
//     }
// 
//   }
// 
// }
// 
// Path: websocket/src/main/java/io/cettia/asity/websocket/ServerWebSocket.java
// public interface ServerWebSocket {
// 
//   /**
//    * The URI used to connect.
//    */
//   String uri();
// 
//   /**
//    * The names of the handshake request headers. HTTP header is not case-sensitive
//    * but {@link Set} is case-sensitive.
//    */
//   Set<String> headerNames();
// 
//   /**
//    * Returns the first handshake request header associated with the given name.
//    */
//   String header(String name);
// 
//   /**
//    * Returns the handshake request headers associated with the given name or empty list
//    * if no header is found.
//    */
//   List<String> headers(String name);
// 
//   /**
//    * Closes the connection. This method has no side effect if called more than
//    * once.
//    */
//   void close();
// 
//   /**
//    * Sends a text frame through the connection.
//    */
//   ServerWebSocket send(String data);
// 
//   /**
//    * Sends a binary frame through the connection.
//    */
//   ServerWebSocket send(ByteBuffer byteBuffer);
// 
//   /**
//    * Attaches an action for the text frame.
//    */
//   ServerWebSocket ontext(Action<String> action);
// 
//   /**
//    * Attaches an action for the binary frame.
//    */
//   ServerWebSocket onbinary(Action<ByteBuffer> action);
// 
//   /**
//    * Attaches an action for the close event. After this event, the instance
//    * shouldn't be used and all the other events will be disabled.
//    */
//   ServerWebSocket onclose(Action<Void> action);
// 
//   /**
//    * Attaches an action to handle error from various things. Its exact
//    * behavior is platform-specific and error created by the platform is
//    * propagated.
//    */
//   ServerWebSocket onerror(Action<Throwable> action);
// 
//   /**
//    * Returns the provider-specific component.
//    */
//   <T> T unwrap(Class<T> clazz);
// 
// }


import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import io.cettia.asity.action.Actions;
import io.cettia.asity.websocket.ServerWebSocket;
import play.http.websocket.Message;
/*
 * Copyright 2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.cettia.asity.bridge.play2;


/**
 * An actor to handle a WebSocket connection.
 *
 * @author Donghwan Kim
 */
public class AsityWebSocketActor extends AbstractActor {

  final ActorRef out;
  private final Actions<ServerWebSocket> actions;
  private final PlayServerWebSocket ws;

// Path: action/src/main/java/io/cettia/asity/action/Actions.java
// public interface Actions<T> {
// 
//   /**
//    * Adds an action.
//    */
//   Actions<T> add(Action<T> action);
// 
//   /**
//    * Disables any operation on the actions. This method is useful when
//    * multiple events are mutually exclusive.
//    */
//   Actions<T> disable();
// 
//   /**
//    * Determines if the actions has been disabled.
//    */
//   boolean disabled();
// 
//   /**
//    * Removes all of the actions.
//    */
//   Actions<T> empty();
// 
//   /**
//    * Fire all of the actions.
//    */
//   Actions<T> fire();
// 
//   /**
//    * Fire all of the actions with the given value.
//    */
//   Actions<T> fire(T data);
// 
//   /**
//    * Determines if the actions have been called at least once.
//    */
//   boolean fired();
// 
//   /**
//    * Determines if the actions contains an action.
//    */
//   boolean has();
// 
//   /**
//    * Determines whether the actions contains the specified action.
//    */
//   boolean has(Action<T> action);
// 
//   /**
//    * Removes an action.
//    */
//   Actions<T> remove(Action<T> action);
// 
//   /**
//    * Options to create an Actions. With the default options, an Action will
//    * work like a typical event manager.
//    *
//    * @author Donghwan Kim
//    */
//   class Options {
// 
//     private boolean once;
//     private boolean memory;
//     private boolean unique;
// 
//     public Options() {
//     }
// 
//     public Options(Options options) {
//       once = options.once;
//       memory = options.memory;
//       unique = options.unique;
//     }
// 
//     public boolean once() {
//       return once;
//     }
// 
//     /**
//      * Ensures the actions can only be fired once. The default value is
//      * false.
//      */
//     public Options once(boolean once) {
//       this.once = once;
//       return this;
//     }
// 
//     public boolean memory() {
//       return memory;
//     }
// 
//     /**
//      * Keeps track of previous values and will call any action added after
//      * the actions has been fired right away with the latest "memorized"
//      * values. The default value is false.
//      */
//     public Options memory(boolean memory) {
//       this.memory = memory;
//       return this;
//     }
// 
//     public boolean unique() {
//       return unique;
//     }
// 
//     /**
//      * Ensures an action can only be added once. The default value is false.
//      */
//     public Options unique(boolean unique) {
//       this.unique = unique;
//       return this;
//     }
// 
//   }
// 
// }
// 
// Path: websocket/src/main/java/io/cettia/asity/websocket/ServerWebSocket.java
// public interface ServerWebSocket {
// 
//   /**
//    * The URI used to connect.
//    */
//   String uri();
// 
//   /**
//    * The names of the handshake request headers. HTTP header is not case-sensitive
//    * but {@link Set} is case-sensitive.
//    */
//   Set<String> headerNames();
// 
//   /**
//    * Returns the first handshake request header associated with the given name.
//    */
//   String header(String name);
// 
//   /**
//    * Returns the handshake request headers associated with the given name or empty list
//    * if no header is found.
//    */
//   List<String> headers(String name);
// 
//   /**
//    * Closes the connection. This method has no side effect if called more than
//    * once.
//    */
//   void close();
// 
//   /**
//    * Sends a text frame through the connection.
//    */
//   ServerWebSocket send(String data);
// 
//   /**
//    * Sends a binary frame through the connection.
//    */
//   ServerWebSocket send(ByteBuffer byteBuffer);
// 
//   /**
//    * Attaches an action for the text frame.
//    */
//   ServerWebSocket ontext(Action<String> action);
// 
//   /**
//    * Attaches an action for the binary frame.
//    */
//   ServerWebSocket onbinary(Action<ByteBuffer> action);
// 
//   /**
//    * Attaches an action for the close event. After this event, the instance
//    * shouldn't be used and all the other events will be disabled.
//    */
//   ServerWebSocket onclose(Action<Void> action);
// 
//   /**
//    * Attaches an action to handle error from various things. Its exact
//    * behavior is platform-specific and error created by the platform is
//    * propagated.
//    */
//   ServerWebSocket onerror(Action<Throwable> action);
// 
//   /**
//    * Returns the provider-specific component.
//    */
//   <T> T unwrap(Class<T> clazz);
// 
// }


// Path: bridge-play2/src/main/java/io/cettia/asity/bridge/play2/AsityWebSocketActor.java
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import io.cettia.asity.action.Actions;
import io.cettia.asity.websocket.ServerWebSocket;
import play.http.websocket.Message;

/*
 * Copyright 2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.cettia.asity.bridge.play2;


/**
 * An actor to handle a WebSocket connection.
 *
 * @author Donghwan Kim
 */
public class AsityWebSocketActor extends AbstractActor {

  final ActorRef out;
  private final Actions<ServerWebSocket> actions;
  private final PlayServerWebSocket ws;

  public AsityWebSocketActor(ActorRef out, Actions<ServerWebSocket> actions, PlayServerWebSocket ws) {