Optimize operation execute
This commit is contained in:
parent
b0d48bef52
commit
23cc2d746f
@ -1,6 +1,7 @@
|
||||
package com.annimon.socketfiletransfer;
|
||||
|
||||
import com.annimon.socketfiletransfer.operations.BrightnessOperation;
|
||||
import com.annimon.socketfiletransfer.operations.CursorOperation;
|
||||
import com.annimon.socketfiletransfer.operations.MessageOperation;
|
||||
import com.annimon.socketfiletransfer.operations.FileOperation;
|
||||
import com.annimon.socketfiletransfer.operations.Operation;
|
||||
@ -37,24 +38,9 @@ public class OperationListener {
|
||||
|
||||
public void listenOperation() throws Exception {
|
||||
int mode = dis.readInt();
|
||||
Operation operation;
|
||||
switch(mode) {
|
||||
case MODE_FILE_TRANSFER:
|
||||
operation = new FileOperation(dis);
|
||||
break;
|
||||
case MODE_MESSAGE_TRANSFER:
|
||||
operation = new MessageOperation(dis);
|
||||
break;
|
||||
// case MODE_CURSOR_CONTROL:
|
||||
// operation = new CursorOperation(dis);
|
||||
// break;
|
||||
case MODE_BRIGHTNESS_CHANGE:
|
||||
operation = new BrightnessOperation(dis);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
Operation operation = getOperation(mode);
|
||||
if (operation != null) {
|
||||
operation.setDataInputStream(dis);
|
||||
operation.startServerSide();
|
||||
}
|
||||
}
|
||||
@ -75,4 +61,24 @@ public class OperationListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Operation getOperation(int mode) {
|
||||
Operation operation = null;
|
||||
switch(mode) {
|
||||
case MODE_FILE_TRANSFER:
|
||||
operation = new FileOperation();
|
||||
break;
|
||||
case MODE_MESSAGE_TRANSFER:
|
||||
operation = new MessageOperation();
|
||||
break;
|
||||
case MODE_CURSOR_CONTROL:
|
||||
operation = new CursorOperation();
|
||||
break;
|
||||
case MODE_BRIGHTNESS_CHANGE:
|
||||
operation = new BrightnessOperation();
|
||||
break;
|
||||
}
|
||||
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.annimon.socketfiletransfer;
|
||||
|
||||
import com.annimon.socketfiletransfer.operations.BrightnessOperation;
|
||||
import com.annimon.socketfiletransfer.operations.CursorOperation;
|
||||
import com.annimon.socketfiletransfer.operations.FileOperation;
|
||||
import com.annimon.socketfiletransfer.operations.MessageOperation;
|
||||
import com.annimon.socketfiletransfer.operations.Operation;
|
||||
|
||||
/**
|
||||
@ -13,22 +9,9 @@ import com.annimon.socketfiletransfer.operations.Operation;
|
||||
public class OperationManager extends OperationListener {
|
||||
|
||||
public void execute(int mode, Object... params) throws Exception {
|
||||
Operation operation = null;
|
||||
switch (mode) {
|
||||
case MODE_FILE_TRANSFER:
|
||||
operation = new FileOperation(dos);
|
||||
break;
|
||||
case MODE_MESSAGE_TRANSFER:
|
||||
operation = new MessageOperation(dos);
|
||||
break;
|
||||
case MODE_CURSOR_CONTROL:
|
||||
operation = new CursorOperation(dos);
|
||||
break;
|
||||
case MODE_BRIGHTNESS_CHANGE:
|
||||
operation = new BrightnessOperation(dos);
|
||||
break;
|
||||
}
|
||||
Operation operation = getOperation(mode);
|
||||
if (operation != null) {
|
||||
operation.setDataOutputStream(dos);
|
||||
operation.startClientSide(params);
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,6 @@ import java.io.DataOutputStream;
|
||||
*/
|
||||
public class BrightnessOperation extends Operation {
|
||||
|
||||
public BrightnessOperation(DataInputStream dis) {
|
||||
this.dis = dis;
|
||||
}
|
||||
|
||||
public BrightnessOperation(DataOutputStream dos) {
|
||||
this.dos = dos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startServerSide() throws Exception {
|
||||
|
||||
|
@ -28,14 +28,6 @@ public class CursorOperation extends Operation {
|
||||
|
||||
private boolean running;
|
||||
|
||||
public CursorOperation(DataInputStream dis) {
|
||||
this.dis = dis;
|
||||
}
|
||||
|
||||
public CursorOperation(DataOutputStream dos) {
|
||||
this.dos = dos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startServerSide() throws Exception {
|
||||
|
||||
|
@ -20,14 +20,6 @@ public class FileOperation extends Operation {
|
||||
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
public FileOperation(DataInputStream dis) {
|
||||
this.dis = dis;
|
||||
}
|
||||
|
||||
public FileOperation(DataOutputStream dos) {
|
||||
this.dos = dos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startServerSide() {
|
||||
FileOutputStream fout = null;
|
||||
|
@ -14,14 +14,6 @@ import java.io.IOException;
|
||||
*/
|
||||
public class MessageOperation extends Operation {
|
||||
|
||||
public MessageOperation(DataInputStream dis) {
|
||||
this.dis = dis;
|
||||
}
|
||||
|
||||
public MessageOperation(DataOutputStream dos) {
|
||||
this.dos = dos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startServerSide() throws IOException {
|
||||
String text = dis.readUTF();
|
||||
|
@ -12,6 +12,14 @@ public abstract class Operation {
|
||||
protected DataInputStream dis;
|
||||
protected DataOutputStream dos;
|
||||
|
||||
public void setDataInputStream(DataInputStream dis) {
|
||||
this.dis = dis;
|
||||
}
|
||||
|
||||
public void setDataOutputStream(DataOutputStream dos) {
|
||||
this.dos = dos;
|
||||
}
|
||||
|
||||
public abstract void startServerSide() throws Exception;
|
||||
|
||||
public abstract void startClientSide(Object... params) throws Exception;
|
||||
|
Loading…
Reference in New Issue
Block a user