Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members

Socket.java

Go to the documentation of this file.
00001 /*
00002  * Socket.java
00003  *
00004  * Created on den 25 oktober 2004, 14:36
00005  */
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008  
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013  
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018  
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022  */
00023 
00024 package net.alhem.jsockets;
00025 
00026 import java.nio.ByteBuffer;
00027 import java.nio.channels.SelectableChannel;
00028 import java.nio.channels.SelectionKey;
00029 import java.nio.channels.SocketChannel;
00030 
00035 public abstract class Socket
00036 {
00037     
00039     public Socket(SocketHandler h)
00040     {
00041         m_handler = h;
00042     } // Socket
00043     public abstract Socket Create();
00044     public abstract void OnInitialOps();
00045 
00046     public void OnRead()
00047     {
00048         Handler().LogError(this, "OnRead", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00049     } // OnRead
00050     public void OnWrite()
00051     {
00052         Handler().LogError(this, "OnWrite", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00053     } // OnWrite
00054     public void OnConnect()
00055     {
00056         Handler().LogError(this, "OnConnect", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00057     } // OnConnect
00058     public void OnAccept()
00059     {
00060         Handler().LogError(this, "OnAccept", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00061     } // OnAccept
00062     public void OnDelete()
00063     {
00064     } // OnDelete
00065     public void ReadLine()
00066     {
00067     } // ReadLine
00068     public void OnLine(String line)
00069     {
00070     } // OnLine
00071     public void OnRawData(ByteBuffer b,int len)
00072     {
00073     } // OnRawData
00074 
00075     // 
00076     public SocketHandler Handler()
00077     {
00078         return m_handler;
00079     } // Handler
00080     
00081     public String toString()
00082     {
00083         return "This is a " + getClass().getSimpleName();
00084     } // toString
00085 
00087     public void attach(SelectableChannel x)
00088     {
00089         m_ch = x;
00090     } // attach
00091     public SelectableChannel GetChannel()
00092     {
00093         return m_ch;
00094     } // GetChannel
00095 
00097     public void SetKey(SelectionKey key)
00098     {
00099         m_key = key;
00100     }
00101     public SelectionKey GetKey()
00102     {
00103         return m_key;
00104     }
00105 
00107     public void SetCloseAndDelete()
00108     {
00109         m_close_and_delete = true;
00110     }
00111     public boolean CloseAndDelete()
00112     {
00113         return m_close_and_delete;
00114     }
00115     
00117     public void SetLineProtocol()
00118     {
00119         m_line_protocol = true;
00120     }
00121     public boolean LineProtocol()
00122     {
00123         return m_line_protocol;
00124     }
00125     public void SetLineProtocol(boolean x)
00126     {
00127         m_line_protocol = x;
00128     }
00129 
00131     public void SetConnecting()
00132     {
00133         m_connecting = true;
00134     }
00135     public void SetConnecting(boolean x)
00136     {
00137         m_connecting = x;
00138     }
00139     public boolean Connecting()
00140     {
00141         return m_connecting;
00142     }
00143     
00144     //
00145     private SocketHandler m_handler;
00146     private SelectableChannel m_ch;
00147     private SelectionKey m_key; // key in Selector
00148     private boolean m_close_and_delete = false;
00149     private boolean m_line_protocol = false;
00150     private boolean m_connecting = false;
00151 }

Generated on Fri Oct 29 14:11:17 2004 for Java Sockets by  doxygen 1.3.9.1