00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 }
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 }
00050 public void OnWrite()
00051 {
00052 Handler().LogError(this, "OnWrite", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00053 }
00054 public void OnConnect()
00055 {
00056 Handler().LogError(this, "OnConnect", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00057 }
00058 public void OnAccept()
00059 {
00060 Handler().LogError(this, "OnAccept", 0, "not implemented", SocketHandler.LOG_LEVEL_INFO);
00061 }
00062 public void OnDelete()
00063 {
00064 }
00065 public void ReadLine()
00066 {
00067 }
00068 public void OnLine(String line)
00069 {
00070 }
00071 public void OnRawData(ByteBuffer b,int len)
00072 {
00073 }
00074
00075
00076 public SocketHandler Handler()
00077 {
00078 return m_handler;
00079 }
00080
00081 public String toString()
00082 {
00083 return "This is a " + getClass().getSimpleName();
00084 }
00085
00087 public void attach(SelectableChannel x)
00088 {
00089 m_ch = x;
00090 }
00091 public SelectableChannel GetChannel()
00092 {
00093 return m_ch;
00094 }
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;
00148 private boolean m_close_and_delete = false;
00149 private boolean m_line_protocol = false;
00150 private boolean m_connecting = false;
00151 }