Changeset 105 for java/main/src/main/java/com/framsticks/communication
- Timestamp:
- 09/10/13 21:11:41 (11 years ago)
- Location:
- java/main/src/main/java/com/framsticks/communication
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r103 r105 9 9 import com.framsticks.communication.queries.UseRequest; 10 10 import com.framsticks.communication.queries.VersionRequest; 11 import com.framsticks.core.Path;12 11 import com.framsticks.params.ListSource; 12 import com.framsticks.structure.Path; 13 13 import com.framsticks.util.*; 14 14 import com.framsticks.util.dispatching.AtOnceDispatcher; 15 15 import com.framsticks.util.dispatching.Dispatcher; 16 16 import com.framsticks.util.dispatching.Dispatching; 17 import com.framsticks.util.dispatching. ExceptionResultHandler;17 import com.framsticks.util.dispatching.FutureHandler; 18 18 import com.framsticks.util.dispatching.Future; 19 import com.framsticks.util.dispatching.FutureHandler;20 19 import com.framsticks.util.dispatching.JoinableState; 21 20 import com.framsticks.util.lang.Casting; … … 195 194 } 196 195 197 private void sendNextUseRequest(final Iterator<String> featuresIterator, final Future <Void> future) {196 private void sendNextUseRequest(final Iterator<String> featuresIterator, final FutureHandler<Void> future) { 198 197 if (!featuresIterator.hasNext()) { 199 198 future.pass(null); … … 214 213 } 215 214 216 private void sendQueryVersion(final int version, final Future <Void> future) {215 private void sendQueryVersion(final int version, final FutureHandler<Void> future) { 217 216 send(new VersionRequest().version(version), new ClientSideResponseFuture(future) { 218 217 @Override … … 335 334 } 336 335 337 final Future <File> future = new Future<File>() {336 final FutureHandler<File> future = new FutureHandler<File>() { 338 337 339 338 protected void send(final File result) { … … 415 414 } 416 415 417 protected final Exception ResultHandler closeOnFailure = new ExceptionResultHandler() {416 protected final ExceptionHandler closeOnFailure = new ExceptionHandler() { 418 417 419 418 @Override … … 428 427 startClientConnection(this); 429 428 430 sendQueryVersion(1, new Future Handler<Void>(closeOnFailure) {429 sendQueryVersion(1, new Future<Void>(closeOnFailure) { 431 430 432 431 @Override … … 451 450 protected final Map<String, EventListener<File>> registeredListeners = new HashMap<>(); 452 451 453 public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final Future <Void> future) {452 public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final FutureHandler<Void> future) { 454 453 send(new RegisterRequest().path(path), dispatcher, new ClientSideResponseFuture(future) { 455 454 @Override … … 463 462 } 464 463 465 public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final Future <Void> future) {464 public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final FutureHandler<Void> future) { 466 465 String eventPath = null; 467 466 synchronized (registeredListeners) { -
java/main/src/main/java/com/framsticks/communication/ClientSideRawConnection.java
r97 r105 2 2 3 3 import com.framsticks.params.annotations.FramsClassAnnotation; 4 import com.framsticks.util. dispatching.ExceptionResultHandler;4 import com.framsticks.util.ExceptionHandler; 5 5 import com.framsticks.util.dispatching.RunAt; 6 6 … … 23 23 } 24 24 25 public void send(final String line, Exception ResultHandler handler) {25 public void send(final String line, ExceptionHandler handler) { 26 26 27 27 senderThread.dispatch(new RunAt<ClientSideRawConnection>(handler) { -
java/main/src/main/java/com/framsticks/communication/ClientSideResponseFuture.java
r98 r105 1 1 package com.framsticks.communication; 2 2 3 import com.framsticks.util.ExceptionHandler; 3 4 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.dispatching.ExceptionResultHandler; 5 import com.framsticks.util.dispatching.FutureHandler; 5 import com.framsticks.util.dispatching.Future; 6 6 7 public abstract class ClientSideResponseFuture extends Future Handler<Response> {7 public abstract class ClientSideResponseFuture extends Future<Response> { 8 8 9 public ClientSideResponseFuture(Exception ResultHandler handler) {9 public ClientSideResponseFuture(ExceptionHandler handler) { 10 10 super(handler); 11 11 } -
java/main/src/main/java/com/framsticks/communication/Connection.java
r102 r105 5 5 import com.framsticks.params.annotations.FramsClassAnnotation; 6 6 import com.framsticks.params.annotations.ParamAnnotation; 7 import com.framsticks.util.ExceptionHandler; 7 8 import com.framsticks.util.FramsticksException; 8 9 import com.framsticks.util.io.Encoding; … … 25 26 import com.framsticks.util.dispatching.Dispatcher; 26 27 import com.framsticks.util.dispatching.Dispatching; 27 import com.framsticks.util.dispatching.ExceptionResultHandler;28 28 import com.framsticks.util.dispatching.Joinable; 29 29 import com.framsticks.util.dispatching.JoinableCollection; … … 35 35 36 36 @FramsClassAnnotation 37 public abstract class Connection extends AbstractJoinable implements JoinableParent, Exception ResultHandler {37 public abstract class Connection extends AbstractJoinable implements JoinableParent, ExceptionHandler { 38 38 39 39 protected final static Logger log = LogManager.getLogger(Connection.class); … … 52 52 protected final Set<ConnectionListener> listeners = new HashSet<>(); 53 53 54 protected Exception ResultHandler exceptionHandler = ThrowExceptionHandler.getInstance();54 protected ExceptionHandler exceptionHandler = ThrowExceptionHandler.getInstance(); 55 55 56 56 /** … … 301 301 * @return the handler 302 302 */ 303 public Exception ResultHandler getExceptionHandler() {303 public ExceptionHandler getExceptionHandler() { 304 304 return exceptionHandler; 305 305 } … … 308 308 * @param handler the handler to set 309 309 */ 310 public void setExceptionHandler(Exception ResultHandler handler) {310 public void setExceptionHandler(ExceptionHandler handler) { 311 311 this.exceptionHandler = handler; 312 312 } … … 346 346 } 347 347 348 public final void sendFile(final String header, final File file, final Integer id, Exception ResultHandler handler) {348 public final void sendFile(final String header, final File file, final Integer id, ExceptionHandler handler) { 349 349 senderThread.dispatch(new RunAt<Connection>(handler) { 350 350 @Override -
java/main/src/main/java/com/framsticks/communication/File.java
r101 r105 1 1 package com.framsticks.communication; 2 2 3 import java.util.ArrayList;4 import java.util.List;5 3 6 4 import javax.annotation.Nonnull; … … 31 29 } 32 30 33 public static List<File> single(File file) {34 List<File> result = new ArrayList<File>();35 result.add(file);36 return result;37 }38 39 31 @Override 40 32 public String toString() { -
java/main/src/main/java/com/framsticks/communication/RequestHandler.java
r98 r105 2 2 3 3 import com.framsticks.communication.queries.ApplicationRequest; 4 import com.framsticks.util. dispatching.ExceptionResultHandler;4 import com.framsticks.util.ExceptionHandler; 5 5 6 6 /** 7 7 * @author Piotr Sniegowski 8 8 */ 9 public interface RequestHandler extends Exception ResultHandler {9 public interface RequestHandler extends ExceptionHandler { 10 10 public void handle(ApplicationRequest request, ServerSideResponseFuture responseCallback); 11 11 } -
java/main/src/main/java/com/framsticks/communication/Response.java
r96 r105 1 1 package com.framsticks.communication; 2 2 3 import java.util.Arrays; 3 4 import java.util.List; 4 5 … … 10 11 protected final String comment; 11 12 protected final List<File> files; 13 14 public Response(boolean ok, String comment, File... files) { 15 this(ok, comment, (files.length == 0 ? null : Arrays.asList(files))); 16 } 12 17 13 18 public Response(boolean ok, String comment, List<File> files) { -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r103 r105 46 46 if (request instanceof ProtocolRequest) { 47 47 if (request instanceof VersionRequest) { 48 responseCallback.pass(new Response(true, null , null));48 responseCallback.pass(new Response(true, null)); 49 49 return; 50 50 } … … 53 53 if (feature.equals("request_id")) { 54 54 requestIdEnabled = true; 55 responseCallback.pass(new Response(true, null , null));55 responseCallback.pass(new Response(true, null)); 56 56 return; 57 57 } 58 58 if (feature.equals("call_empty_result")) { 59 responseCallback.pass(new Response(true, null , null));59 responseCallback.pass(new Response(true, null)); 60 60 return; 61 61 } 62 62 if (feature.equals("needfile_id")) { 63 responseCallback.pass(new Response(true, null , null));63 responseCallback.pass(new Response(true, null)); 64 64 return; 65 65 } 66 responseCallback.pass(new Response(false, "unknown feature: " + feature , null));66 responseCallback.pass(new Response(false, "unknown feature: " + feature)); 67 67 return; 68 68 } … … 70 70 } 71 71 log.error("unhandled request: {}", request); 72 responseCallback.pass(new Response(false, "unhandled" , null));72 responseCallback.pass(new Response(false, "unhandled")); 73 73 } 74 74 … … 120 120 e.arg("id", id.get()).arg("line", line); 121 121 log.error("error: ", e); 122 respond(new Response(false, "invalid input: " + e.getMsg() , null), id.get());122 respond(new Response(false, "invalid input: " + e.getMsg()), id.get()); 123 123 return; 124 124 } -
java/main/src/main/java/com/framsticks/communication/ServerSideResponseFuture.java
r99 r105 2 2 3 3 import com.framsticks.util.FramsticksException; 4 import com.framsticks.util.dispatching.Future ;4 import com.framsticks.util.dispatching.FutureHandler; 5 5 6 6 /** 7 7 * @author Piotr Sniegowski 8 8 */ 9 public abstract class ServerSideResponseFuture extends Future <Response> {9 public abstract class ServerSideResponseFuture extends FutureHandler<Response> { 10 10 11 11 @Override 12 12 public final void handle(FramsticksException e) { 13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getMessage() , null));13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getMessage())); 14 14 } 15 15 -
java/main/src/main/java/com/framsticks/communication/queries/NeedFile.java
r101 r105 2 2 3 3 import com.framsticks.communication.File; 4 import com.framsticks.util.dispatching.Future ;4 import com.framsticks.util.dispatching.FutureHandler; 5 5 import com.framsticks.util.lang.Strings; 6 6 … … 9 9 protected final String suggestedName; 10 10 protected final String description; 11 protected final Future <File> future;11 protected final FutureHandler<File> future; 12 12 13 13 /** … … 16 16 * @param future 17 17 */ 18 public NeedFile(String suggestedName, String description, Future <File> future) {18 public NeedFile(String suggestedName, String description, FutureHandler<File> future) { 19 19 this.suggestedName = suggestedName; 20 20 this.description = description; … … 39 39 * @return the future 40 40 */ 41 public Future <File> getFuture() {41 public FutureHandler<File> getFuture() { 42 42 return future; 43 43 } -
java/main/src/main/java/com/framsticks/communication/queries/RegisterRequest.java
r99 r105 1 1 package com.framsticks.communication.queries; 2 2 3 import com.framsticks. core.Path;3 import com.framsticks.structure.Path; 4 4 import com.framsticks.util.lang.Pair; 5 5
Note: See TracChangeset
for help on using the changeset viewer.