Instance.java

  1. /*******************************************************************************
  2.  * Copyright (c) 2004, 2013 Steve Flasby
  3.  * All rights reserved.
  4.  * Redistribution and use in source and binary forms, with or without modification,
  5.  * are permitted provided that the following conditions are met:
  6.  * <ul>
  7.  *     <li>Redistributions of source code must retain the above copyright notice,
  8.  *         this list of conditions and the following disclaimer.</li>
  9.  *     <li>Redistributions in binary form must reproduce the above copyright notice,
  10.  *         this list of conditions and the following disclaimer in the documentation
  11.  *         and/or other materials provided with the distribution.</li>
  12.  * </ul>
  13.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16.  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  17.  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20.  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  21.  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23.  ******************************************************************************/
  24. package org.flasby.server;

  25. import java.io.IOException;
  26. import java.net.Socket;

  27. import org.flasby.util.Lifecycle;

  28. public abstract class Instance implements Lifecycle {
  29.     private static int ID=1;

  30.     protected final int mInstanceId;
  31.     protected final Socket mS;
  32.     protected final Reporter mReporter;

  33.     protected Instance(Socket s, Reporter reporter){
  34.         mS = s;
  35.         mReporter = reporter;
  36.         mInstanceId=ID++;
  37.     }
  38.     @Override
  39.     public abstract void start() throws StartFailedException;
  40.    
  41.     @Override
  42.     public void stop() {
  43.         try {
  44.             mS.close();
  45.         } catch (IOException e) {
  46.             e.printStackTrace();
  47.         }
  48.     }
  49.     public Reporter getReporter() {
  50.         return mReporter;
  51.     }

  52. }