// Path: src/main/java/com/goodow/realtime/channel/BusHook.java
// public interface BusHook {
//   /**
//    * Called when the bus is opened
//    */
//   void handleOpened();
// 
//   /**
//    * Called when the bus is closed
//    */
//   void handlePostClose();
// 
//   /**
//    * Called before close the bus
//    * 
//    * @return true to close the bus, false to reject it
//    */
//   boolean handlePreClose();
// 
//   /**
//    * Called before register a handler
//    * 
//    * @param topic The topic
//    * @param handler The handler
//    * @return true to let the registration occur, false otherwise
//    */
//   @SuppressWarnings("rawtypes")
//   boolean handlePreSubscribe(String topic, Handler<? extends Message> handler);
// 
//   /**
//    * Called when a message is received
//    * 
//    * @param message The message
//    * @return true To allow the message to deliver, false otherwise
//    */
//   boolean handleReceiveMessage(Message<?> message);
// 
//   /**
//    * Called when sending or publishing on the bus
//    * 
//    * @param send if true it's a send else it's a publish
//    * @param topic The topic the message is being sent/published to
//    * @param msg The message
//    * @param replyHandler Reply handler will be called when any reply from the recipient is received
//    * @return true To allow the send/publish to occur, false otherwise
//    */
//   <T> boolean handleSendOrPub(boolean send, String topic, Object msg,
//       Handler<Message<T>> replyHandler);
// 
//   /**
//    * Called when unregistering a handler
//    * 
//    * @param topic The topic
//    * @return true to let the unregistration occur, false otherwise
//    */
//   boolean handleUnsubscribe(String topic);
// }
// 
// Path: src/main/java/com/goodow/realtime/channel/Message.java
// @JsType
// public interface Message<T> {
//   /**
//    * The body of the message
//    */
//   T body();
// 
//   /**
//    * Signal that processing of this message failed. If the message was sent specifying a result
//    * handler the handler will be called with a failure corresponding to the failure code and message
//    * specified here
//    *
//    * @param failureCode A failure code to pass back to the sender
//    * @param msg A message to pass back to the sender
//    */
//   void fail(int failureCode, String msg);
// 
//   /**
//    * @return Whether this message originated in the local session.
//    */
//   boolean isLocal();
// 
//   /**
//    * Reply to this message. If the message was sent specifying a reply handler, that handler will be
//    * called when it has received a reply. If the message wasn't sent specifying a receipt handler
//    * this method does nothing.
//    */
//   @JsNoExport
//   void reply(Object msg);
// 
//   /**
//    * The same as {@code reply(Object msg)} but you can specify handler for the reply - i.e. to
//    * receive the reply to the reply.
//    */
//   @SuppressWarnings("hiding")
//   <T> void reply(Object msg, Handler<Message<T>> replyHandler);
// 
//   /**
//    * The reply topic (if any)
//    */
//   String replyTopic();
// 
//   /**
//    * The topic the message was sent to
//    */
//   String topic();
// }
// 
// Path: src/main/java/com/goodow/realtime/core/Handler.java
// public interface Handler<E> {
// 
//   /**
//    * Something has happened, so handle it.
//    */
//   void handle(E event);
// }


import com.goodow.realtime.channel.Message;
import com.goodow.realtime.core.Handler;
import com.goodow.realtime.channel.BusHook;
/*
 * Copyright 2014 Goodow.com
 *
 * 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 com.goodow.realtime.channel.impl;


public abstract class BusHookProxy implements BusHook {
  @Override
  public void handleOpened() {
    if (delegate() != null) {
      delegate().handleOpened();
    }
  }

  @Override
  public void handlePostClose() {
    if (delegate() != null) {
      delegate().handlePostClose();
    }
  }

  @Override
  public boolean handlePreClose() {
    return delegate() == null ? true : delegate().handlePreClose();
  }

  @SuppressWarnings("rawtypes")
  @Override
  public boolean handlePreSubscribe(String topic, Handler<? extends Message> handler) {
    return delegate() == null ? true : delegate().handlePreSubscribe(topic, handler);
  }

  @Override
  public boolean handleReceiveMessage(Message<?> message) {
    return delegate() == null ? true : delegate().handleReceiveMessage(message);
  }

  @Override
  public <T> boolean handleSendOrPub(boolean send, String topic, Object msg,
// Path: src/main/java/com/goodow/realtime/channel/BusHook.java
// public interface BusHook {
//   /**
//    * Called when the bus is opened
//    */
//   void handleOpened();
// 
//   /**
//    * Called when the bus is closed
//    */
//   void handlePostClose();
// 
//   /**
//    * Called before close the bus
//    * 
//    * @return true to close the bus, false to reject it
//    */
//   boolean handlePreClose();
// 
//   /**
//    * Called before register a handler
//    * 
//    * @param topic The topic
//    * @param handler The handler
//    * @return true to let the registration occur, false otherwise
//    */
//   @SuppressWarnings("rawtypes")
//   boolean handlePreSubscribe(String topic, Handler<? extends Message> handler);
// 
//   /**
//    * Called when a message is received
//    * 
//    * @param message The message
//    * @return true To allow the message to deliver, false otherwise
//    */
//   boolean handleReceiveMessage(Message<?> message);
// 
//   /**
//    * Called when sending or publishing on the bus
//    * 
//    * @param send if true it's a send else it's a publish
//    * @param topic The topic the message is being sent/published to
//    * @param msg The message
//    * @param replyHandler Reply handler will be called when any reply from the recipient is received
//    * @return true To allow the send/publish to occur, false otherwise
//    */
//   <T> boolean handleSendOrPub(boolean send, String topic, Object msg,
//       Handler<Message<T>> replyHandler);
// 
//   /**
//    * Called when unregistering a handler
//    * 
//    * @param topic The topic
//    * @return true to let the unregistration occur, false otherwise
//    */
//   boolean handleUnsubscribe(String topic);
// }
// 
// Path: src/main/java/com/goodow/realtime/channel/Message.java
// @JsType
// public interface Message<T> {
//   /**
//    * The body of the message
//    */
//   T body();
// 
//   /**
//    * Signal that processing of this message failed. If the message was sent specifying a result
//    * handler the handler will be called with a failure corresponding to the failure code and message
//    * specified here
//    *
//    * @param failureCode A failure code to pass back to the sender
//    * @param msg A message to pass back to the sender
//    */
//   void fail(int failureCode, String msg);
// 
//   /**
//    * @return Whether this message originated in the local session.
//    */
//   boolean isLocal();
// 
//   /**
//    * Reply to this message. If the message was sent specifying a reply handler, that handler will be
//    * called when it has received a reply. If the message wasn't sent specifying a receipt handler
//    * this method does nothing.
//    */
//   @JsNoExport
//   void reply(Object msg);
// 
//   /**
//    * The same as {@code reply(Object msg)} but you can specify handler for the reply - i.e. to
//    * receive the reply to the reply.
//    */
//   @SuppressWarnings("hiding")
//   <T> void reply(Object msg, Handler<Message<T>> replyHandler);
// 
//   /**
//    * The reply topic (if any)
//    */
//   String replyTopic();
// 
//   /**
//    * The topic the message was sent to
//    */
//   String topic();
// }
// 
// Path: src/main/java/com/goodow/realtime/core/Handler.java
// public interface Handler<E> {
// 
//   /**
//    * Something has happened, so handle it.
//    */
//   void handle(E event);
// }


// Path: src/main/java/com/goodow/realtime/channel/impl/BusHookProxy.java
import com.goodow.realtime.channel.Message;
import com.goodow.realtime.core.Handler;
import com.goodow.realtime.channel.BusHook;

/*
 * Copyright 2014 Goodow.com
 *
 * 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 com.goodow.realtime.channel.impl;


public abstract class BusHookProxy implements BusHook {
  @Override
  public void handleOpened() {
    if (delegate() != null) {
      delegate().handleOpened();
    }
  }

  @Override
  public void handlePostClose() {
    if (delegate() != null) {
      delegate().handlePostClose();
    }
  }

  @Override
  public boolean handlePreClose() {
    return delegate() == null ? true : delegate().handlePreClose();
  }

  @SuppressWarnings("rawtypes")
  @Override
  public boolean handlePreSubscribe(String topic, Handler<? extends Message> handler) {
    return delegate() == null ? true : delegate().handlePreSubscribe(topic, handler);
  }

  @Override
  public boolean handleReceiveMessage(Message<?> message) {
    return delegate() == null ? true : delegate().handleReceiveMessage(message);
  }

  @Override
  public <T> boolean handleSendOrPub(boolean send, String topic, Object msg,
      Handler<Message<T>> replyHandler) {