17c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet/*
27c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * Copyright (C) 2009 Google Inc.  All rights reserved.
37c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet *
47c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * Licensed under the Apache License, Version 2.0 (the "License");
57c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * you may not use this file except in compliance with the License.
67c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * You may obtain a copy of the License at
77c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet *
87c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet *      http://www.apache.org/licenses/LICENSE-2.0
97c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet *
107c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * Unless required by applicable law or agreed to in writing, software
117c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * distributed under the License is distributed on an "AS IS" BASIS,
127c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * See the License for the specific language governing permissions and
147c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * limitations under the License.
157c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet */
167c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
177c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichetpackage com.google.polo.wire;
187c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
197c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichetimport java.io.IOException;
207c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
217c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichetimport com.google.polo.exception.PoloException;
227c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichetimport com.google.polo.pairing.message.PoloMessage;
237c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
247c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet/**
257c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * Public interface for transport-layer implementations of the pairing
267c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet * protocol.
277c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet */
287c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichetpublic interface PoloWireInterface {
297c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
307c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  /**
317c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * Returns the next message from the wire.
327c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   *
337c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @return a new PoloMessage instance
347c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws IOException  if an error occurred while reading
357c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws PoloException  if a protocol fault occurred
367c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   */
377c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  public PoloMessage getNextMessage() throws IOException, PoloException;
387c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
397c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  /**
407c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * Returns the next message from the wire.
417c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   *
427c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @param type  the required message type to be read
437c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @return a new PoloMessage instance
447c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws IOException  if an error occurred while reading
457c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws PoloException  if the next message did not match the requested
467c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   *                        type.
477c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   */
487c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  public PoloMessage getNextMessage(PoloMessage.PoloMessageType type)
497c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet      throws IOException, PoloException;
507c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
517c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  /**
527c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * Send a normal message out on the wire.
537c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   *
547c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @param message  the message to send
557c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws IOException  if an error occurred while sending
567c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws PoloException  if the message was not well formed
577c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   */
587c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  public void sendMessage(PoloMessage message)
597c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet      throws IOException, PoloException;
607c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
617c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  /**
627c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * Send an error message out on the wire, based on an exception.
637c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   *
647c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @param e  the exception causing the error
657c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   * @throws IOException  if an error occurred while sending
667c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet   */
677c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet  public void sendErrorMessage(Exception e) throws IOException;
687c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet
697c9978567a202d6aa98beac5da5e1b3b34792862Jerome Poichet}
70