Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaodx committed May 28, 2018
1 parent 6b24309 commit 1a2e2d5
Show file tree
Hide file tree
Showing 43 changed files with 529 additions and 471 deletions.
48 changes: 24 additions & 24 deletions fpnn-lib/src/main/java/com/fpnn/FPClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.fpnn;

import com.fpnn.callback.CallbackData;
import com.fpnn.callback.FPCallback;
import com.fpnn.callback.FPCallbackManager;
import com.fpnn.encryptor.FPEncryptor;
import com.fpnn.event.EventData;
import com.fpnn.event.FPEvent;
import com.fpnn.event.FPEventManager;
import com.fpnn.nio.NIOCore;

import java.io.IOException;
Expand Down Expand Up @@ -35,9 +35,9 @@ public interface IKeyData {

private FPPackage _pkg = new FPPackage();
private FPEncryptor _cyr = new FPEncryptor(_pkg);
private FPEventManager _event = new FPEventManager();
private FPEvent _event = new FPEvent();
private FPProcessor _psr = new FPProcessor();
private FPCallbackManager _callback = new FPCallbackManager();
private FPCallback _callback = new FPCallback();

private long _intervalID = 0;

Expand Down Expand Up @@ -66,7 +66,7 @@ protected void init(String host, int port, boolean autoReconnect, int connection
NIOCore.getInstance().getEvent().addListener("second", new FPEvent.IListener() {

@Override
public void fpEvent(FPEvent event) {
public void fpEvent(EventData event) {

self.onSecond(event.getTimestamp());
}
Expand All @@ -84,7 +84,7 @@ public void onData(SocketChannel socket) {
FPEvent.IListener listener = new FPEvent.IListener() {

@Override
public void fpEvent(FPEvent event) {
public void fpEvent(EventData event) {

switch (event.getType()) {
case "connect":
Expand All @@ -105,7 +105,7 @@ public void fpEvent(FPEvent event) {
this._sock.getEvent().addListener("error", listener);
}

public FPEventManager getEvent() {
public FPEvent getEvent() {

return this._event;
}
Expand Down Expand Up @@ -174,9 +174,9 @@ public void sendQuest(FPData data) {
this.sendQuest(data, null, 0);
}

public FPCallback sendQuest(FPData data, int timeout) throws InterruptedException {
public CallbackData sendQuest(FPData data, int timeout) throws InterruptedException {

FPCallback fpcb = null;
CallbackData cbd = null;

SyncCallbak syncCallbak = new SyncCallbak();
this.sendQuest(data, syncCallbak, timeout);
Expand All @@ -188,10 +188,10 @@ public FPCallback sendQuest(FPData data, int timeout) throws InterruptedExceptio
syncCallbak.wait();
}

fpcb = syncCallbak.getReturn();
cbd = syncCallbak.getReturn();
}

return fpcb;
return cbd;
}

public void sendQuest(FPData data, FPCallback.ICallback callback) {
Expand Down Expand Up @@ -276,9 +276,9 @@ private void sendkey() {
this.sendQuest(data, new FPCallback.ICallback() {

@Override
public void callback(FPCallback fpcb) {
public void callback(CallbackData cbd) {

self.onSendKey(fpcb.getData());
self.onSendKey(cbd.getData());
}
}, this._timeout);

Expand All @@ -287,7 +287,7 @@ public void callback(FPCallback fpcb) {
}

this._intervalID = 0;
this._event.fireEvent(new FPEvent(this, "connect"));
this._event.fireEvent(new EventData(this, "connect"));
}

private void onSendKey(FPData data) {
Expand All @@ -297,7 +297,7 @@ private void onSendKey(FPData data) {
if (!data.jsonPayload().trim().equals("{}")) {

this._cyr.setCryptoed(false);
this._event.fireEvent(new FPEvent(this, "error", new Exception("wrong cryptor!")));
this._event.fireEvent(new EventData(this, "error", new Exception("wrong cryptor!")));
return;
}
}
Expand All @@ -307,13 +307,13 @@ private void onSendKey(FPData data) {
if (data.msgpackPayload().length != 1) {

this._cyr.setCryptoed(false);
this._event.fireEvent(new FPEvent(this, "error", new Exception("wrong cryptor!")));
this._event.fireEvent(new EventData(this, "error", new Exception("wrong cryptor!")));
return;
}
}

this._intervalID = 0;
this._event.fireEvent(new FPEvent(this, "connect"));
this._event.fireEvent(new EventData(this, "connect"));
}

private void onConnect() {
Expand All @@ -330,7 +330,7 @@ private void onClose() {
this._callback.removeCallback();
this._cyr.clear();

this._event.fireEvent(new FPEvent(this, "close"));
this._event.fireEvent(new EventData(this, "close"));

if (this._autoReconnect) {

Expand Down Expand Up @@ -452,7 +452,7 @@ private void execCallback(FPData answer) {
private void onError(Exception ex) {

ex.printStackTrace();
this._event.fireEvent(new FPEvent(this, "error", ex));
this._event.fireEvent(new EventData(this, "error", ex));
}

private void onSecond(long timestamp) {
Expand Down Expand Up @@ -506,20 +506,20 @@ private void reConnect() {

class SyncCallbak implements FPCallback.ICallback {

private FPCallback _fpcb;
private CallbackData _cbd;

@Override
public void callback(FPCallback fpcb) {
public void callback(CallbackData cbd) {

synchronized (this) {

this._fpcb = fpcb;
this._cbd = cbd;
this.notifyAll();
}
}

public FPCallback getReturn() {
public CallbackData getReturn() {

return this._fpcb;
return this._cbd;
}
}
12 changes: 6 additions & 6 deletions fpnn-lib/src/main/java/com/fpnn/FPProcessor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fpnn;

import com.fpnn.event.EventData;
import com.fpnn.event.FPEvent;
import com.fpnn.event.FPEventManager;

public class FPProcessor {

Expand All @@ -13,14 +13,14 @@ public interface IProcessor {
}

private IProcessor _processor;
private FPEventManager _event;
private FPEvent _event;

public FPProcessor() {

this._event = new FPEventManager();
this._event = new FPEvent();
}

public FPEventManager getEvent() {
public FPEvent getEvent() {

return this._event;
}
Expand All @@ -43,12 +43,12 @@ public void service(FPData data, FPClient.IAnswer answer) {

if (data.getFlag() == 0) {

self._event.fireEvent(new FPEvent(this, data.getMethod(), data.jsonPayload()));
self._event.fireEvent(new EventData(this, data.getMethod(), data.jsonPayload()));
}

if (data.getFlag() == 1) {

self._event.fireEvent(new FPEvent(this, data.getMethod(), data.msgpackPayload()));
self._event.fireEvent(new EventData(this, data.getMethod(), data.msgpackPayload()));
}
}

Expand Down
14 changes: 7 additions & 7 deletions fpnn-lib/src/main/java/com/fpnn/FPSocket.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fpnn;

import com.fpnn.event.EventData;
import com.fpnn.event.FPEvent;
import com.fpnn.event.FPEventManager;
import com.fpnn.nio.NIOCore;
import com.fpnn.nio.ThreadPool;

Expand Down Expand Up @@ -31,7 +31,7 @@ public interface IRecvData {

private long _expire = 0;
private boolean _isClosed = true;
private FPEventManager _event;
private FPEvent _event;

private ByteBuffer _sendBuffer = null;
private List _sendQueue = new ArrayList();
Expand All @@ -41,11 +41,11 @@ public FPSocket(IRecvData recvData, String host, int port, int timeout) {
this._host = host;
this._port = port;
this._timeout = timeout;
this._event = new FPEventManager();
this._event = new FPEvent();
this._recvData = recvData;
}

public FPEventManager getEvent() {
public FPEvent getEvent() {

return this._event;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ private SocketChannel initConnect() throws IOException {
private void onConnect() {

this._expire = 0;
this._event.fireEvent(new FPEvent(this, "connect"));
this._event.fireEvent(new EventData(this, "connect"));
}

private void onClose(Exception ex) {
Expand All @@ -266,7 +266,7 @@ private void onClose(Exception ex) {
this.onError(ex);
}

this._event.fireEvent(new FPEvent(this, "close"));
this._event.fireEvent(new EventData(this, "close"));
}

private void onData(SocketChannel socket) {
Expand All @@ -276,7 +276,7 @@ private void onData(SocketChannel socket) {

private void onError(Exception ex) {

this._event.fireEvent(new FPEvent(this, "error", ex));
this._event.fireEvent(new EventData(this, "error", ex));
}

public void onSecond(long timestamp) {
Expand Down
68 changes: 68 additions & 0 deletions fpnn-lib/src/main/java/com/fpnn/callback/CallbackData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.fpnn.callback;

import com.fpnn.FPData;

import java.util.Map;

public class CallbackData {

private FPData _data = null;

public FPData getData() {

return this._data;
}

public CallbackData(FPData data) {

this._data = data;
}


private Exception _exception = null;

public Exception getException() {

return this._exception;
}

public CallbackData(Exception ex) {

this._exception = ex;
}


private Object _payload = null;

public Object getPayload() {

return this._payload;
}

public CallbackData(Object payload) {

this._payload = payload;
}


public void checkException(Map data) {

if (this._exception == null) {

if (data == null) {

this._exception = new Exception("data is null!");
} else if (data.containsKey("code") && data.containsKey("ex")) {

this._exception = new Exception("code: ".concat(data.get("code").toString()).concat(", ex: ").concat(data.get("ex").toString()));
}
}

if (this._exception == null) {

this._payload = data;
}

this._data = null;
}
}
Loading

0 comments on commit 1a2e2d5

Please sign in to comment.