- Timestamp:
- 09/10/13 21:11:41 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java
r103 r105 1 1 package com.framsticks.hosting; 2 2 3 import static com.framsticks.structure.TreeOperations.*; 3 4 import static com.framsticks.util.lang.Strings.assureNotEmpty; 4 5 … … 10 11 import com.framsticks.communication.queries.RegisterRequest; 11 12 import com.framsticks.communication.queries.SetRequest; 12 import com.framsticks.core.LocalTree;13 import com.framsticks.core.Tree;14 import com.framsticks.core.Path;15 13 import com.framsticks.params.*; 16 14 import com.framsticks.params.types.EventParam; 17 15 import com.framsticks.params.types.ProcedureParam; 18 16 import com.framsticks.parsers.Savers; 17 import com.framsticks.structure.LocalTree; 18 import com.framsticks.structure.Path; 19 import com.framsticks.structure.Tree; 20 import com.framsticks.util.ExceptionHandler; 19 21 import com.framsticks.util.FramsticksException; 20 22 import com.framsticks.util.Misc; 21 23 import com.framsticks.util.dispatching.AbstractJoinable; 22 24 import com.framsticks.util.dispatching.Dispatching; 23 import com.framsticks.util.dispatching.ExceptionResultHandler; 24 import com.framsticks.util.dispatching.FutureHandler; 25 import com.framsticks.util.dispatching.Future; 25 26 import com.framsticks.util.dispatching.Joinable; 26 27 import com.framsticks.util.dispatching.JoinableParent; … … 29 30 import com.framsticks.util.lang.Strings; 30 31 31 import static com.framsticks.core.TreeOperations.*;32 32 import static com.framsticks.params.AccessOperations.*; 33 import static com.framsticks.params.ParamsUtil.getParam; 33 34 34 35 import java.net.Socket; … … 37 38 * @author Piotr Sniegowski 38 39 */ 39 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, Exception ResultHandler {40 public class ClientAtServer extends AbstractJoinable implements RequestHandler, JoinableParent, ExceptionHandler { 40 41 41 42 protected final Server server; … … 126 127 protected void handleInTree(final Tree tree, final ApplicationRequest request, final ServerSideResponseFuture responseCallback, final String usedPrefix) { 127 128 128 tryGet(tree, request.getActualPath(), new Future Handler<Path>(responseCallback) {129 tryGet(tree, request.getActualPath(), new Future<Path>(responseCallback) { 129 130 @Override 130 131 protected void result(final Path path) { … … 142 143 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path); 143 144 } 144 responseCallback.pass(new Response(true, "", File.single(printToFile(path.getTextual(), access))));145 responseCallback.pass(new Response(true, "", printToFile(path.getTextual(), access))); 145 146 146 147 return; … … 149 150 if (request instanceof SetRequest) { 150 151 SetRequest setRequest = (SetRequest) request; 151 tree.set(path, access.getFramsClass().getParamEntry(setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new FutureHandler<Integer>(responseCallback) {152 tree.set(path, getParam(access, setRequest.getField(), PrimitiveParam.class), setRequest.getValue(), new Future<Integer>(responseCallback) { 152 153 @Override 153 154 protected void result(Integer flag) { 154 responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null), null)); 155 155 responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null))); 156 156 } 157 157 }); … … 161 161 if (request instanceof CallRequest) { 162 162 final CallRequest callRequest = (CallRequest) request; 163 tree.call(path, access.getFramsClass().getParamEntry(callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), Object.class, new FutureHandler<Object>(responseCallback) {163 tree.call(path, getParam(access, callRequest.getProcedure(), ProcedureParam.class), callRequest.getArguments().toArray(), Object.class, new Future<Object>(responseCallback) { 164 164 @Override 165 protected void result(Object result) { 166 ListSink sink = new ListSink(); 167 sink.print("Result:").breakLine(); 168 sink.print("value:"); 169 sink.print("["); 170 if (result != null) { 171 sink.print(result); 165 protected void result(final Object result) { 166 if (result == null) { 167 responseCallback.pass(new Response(true, "")); 168 return; 172 169 } 173 sink.print("]"); 174 175 responseCallback.pass(new Response(true, "", File.single(new File("", new ListSource(sink.getOut()))))); 170 final Object wrapped = AccessOperations.wrapValueInResultIfPrimitive(result); 171 final File file = AccessOperations.convert(File.class, wrapped, tree.getRegistry()); 172 responseCallback.pass(new Response(true, "", file)); 173 176 174 } 177 175 }); … … 184 182 throw new FramsticksException().msg("info should be available"); 185 183 } 186 responseCallback.pass(new Response(true, null, File.single(new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))));184 responseCallback.pass(new Response(true, null, new File(path.getTextual(), new ListSource(Savers.saveFramsClass(new ListSink(), framsClass).getOut())))); 187 185 return; 188 186 } … … 191 189 RegisterRequest register = (RegisterRequest) request; 192 190 193 cliObject.addListener(path, access.getFramsClass().getParamEntry(register.getEventName(), EventParam.class), usedPrefix, responseCallback);191 cliObject.addListener(path, getParam(access, register.getEventName(), EventParam.class), usedPrefix, responseCallback); 194 192 return; 195 193 }
Note: See TracChangeset
for help on using the changeset viewer.