1 module hunt.imf.protocol.http.HttpConnectionEventHandler; 2 3 import hunt.logging; 4 import hunt.net; 5 import hunt.imf.MessageBuffer; 6 import hunt.imf.ConnectBase; 7 import hunt.imf.protocol.http.HttpConnection; 8 import hunt.imf.ConnectionEventBaseHandler; 9 10 class HttpConnectionEventHandler : ConnectionEventBaseHandler { 11 12 this() { 13 } 14 15 override 16 void connectionOpened(Connection connection) 17 { 18 if (_onConnection !is null) 19 { 20 auto conn = new HttpConnection(connection); 21 _onConnection(conn); 22 } 23 } 24 25 override 26 void connectionClosed(Connection connection) 27 { 28 if (_onClosed !is null ) 29 { 30 auto conn = new HttpConnection(connection); 31 _onClosed(conn); 32 } 33 } 34 35 override 36 void messageReceived(Connection connection, Object message) 37 { 38 MessageBuffer msg = cast(MessageBuffer)message; 39 if (connection.getAttribute("CLIENT") !is null) 40 { 41 if (_onMessage !is null) 42 { 43 _onMessage(connection,message); 44 } 45 } 46 else 47 { 48 ConnectBase.dispatchMessage(new HttpConnection(connection),msg); 49 } 50 } 51 52 override 53 void exceptionCaught(Connection connection, Throwable t) 54 { 55 56 } 57 58 override 59 void failedOpeningConnection(int connectionId, Throwable t) { } 60 61 override 62 void failedAcceptingConnection(int connectionId, Throwable t) { } 63 64 override 65 void setOnConnection(ConnCallBack callback) 66 { 67 _onConnection = callback; 68 } 69 70 override 71 void setOnClosed(ConnCallBack callback) 72 { 73 _onClosed = callback; 74 } 75 76 override 77 void setOnMessage(MsgCallBack callback) 78 { 79 _onMessage = callback; 80 } 81 82 private 83 { 84 string _tag = null; 85 ConnCallBack _onConnection = null; 86 ConnCallBack _onClosed = null; 87 MsgCallBack _onMessage = null; 88 } 89 90 } 91