Changeset 84 for java/main/src/main/java/com/framsticks/hosting
- Timestamp:
- 06/22/13 21:51:33 (11 years ago)
- Location:
- java/main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
java/main/src/main/java/com/framsticks/hosting/InstanceClient.java
r77 r84 9 9 import com.framsticks.parsers.Savers; 10 10 import com.framsticks.core.LocalInstance; 11 import com.framsticks.util. Future;11 import com.framsticks.util.dispatching.Future; 12 12 13 13 import java.net.Socket; … … 21 21 public class InstanceClient implements RequestHandler { 22 22 23 24 23 protected final LocalInstance instance; 24 protected final ServerConnection connection; 25 25 26 27 28 29 30 26 public InstanceClient(LocalInstance instance, Socket socket) { 27 this.instance = instance; 28 connection = new ServerConnection(socket, this); 29 connection.start(); 30 } 31 31 32 33 34 35 32 @Override 33 public String toString() { 34 return instance + "|" + connection.toString(); 35 } 36 36 37 37 38 39 40 41 42 43 final Path path = new Path(instance,request.getPath());44 45 46 47 48 49 50 51 52 53 54 55 56 57 38 @Override 39 public void handle(final ApplicationRequest request, final ResponseCallback responseCallback) { 40 instance.invokeLater(new Runnable() { 41 @Override 42 public void run() { 43 final Path path = instance.getPath(request.getPath()); 44 if (!path.isResolved(request.getPath())) { 45 responseCallback.process(new Response(false, "\"invalid path\"", null)); 46 return; 47 } 48 if (request instanceof GetRequest) { 49 instance.findInfo(path, new Future<FramsClass>() { 50 @Override 51 public void result(FramsClass result, Exception e) { 52 if (result == null) { 53 responseCallback.process(new Response(false, "\"failed to find info for access bind\"", null)); 54 return; 55 } 56 List<File> files = new LinkedList<File>(); 57 AccessInterface access = instance.bindAccess(path); 58 58 59 59 if (access == null) { 60 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 61 responseCallback.process(new Response(false, "\"failed to bind access\"", null)); 62 return; 63 } 64 ListSink sink = new ListSink(); 65 access.save(sink); 66 files.add(new File(path.getTextual(), new ListSource(sink.getOut()))); 67 responseCallback.process(new Response(true, "", files)); 68 } 69 }); 70 return; 71 } 72 if (request instanceof InfoRequest) { 73 instance.findInfo(path, new Future<FramsClass>() { 74 @Override 75 public void result(FramsClass result, Exception e) { 76 if (result == null) { 77 responseCallback.process(new Response(false, "\"info not found\"", null)); 78 return; 79 } 80 ListSink sink = new ListSink(); 81 Savers.saveFramsClass(sink, result); 82 List<File> files = new ArrayList<File>(); 83 files.add(new File(path.getTextual(), new ListSource(sink.getOut()))); 84 responseCallback.process(new Response(true, null, files)); 85 } 86 }); 87 return; 88 } 89 responseCallback.process(new Response(false, "invalid", null)); 90 } 91 }); 92 92 93 93 } 94 94 } -
java/main/src/main/java/com/framsticks/hosting/ServerInstance.java
r78 r84 2 2 3 3 import com.framsticks.core.*; 4 import com.framsticks.params.CompositeParam; 4 5 import com.framsticks.params.FramsClass; 5 6 import com.framsticks.params.ParamBuilder; 6 import com.framsticks.params.types.CompositeParam;7 7 import com.framsticks.core.LocalInstance; 8 import com.framsticks.util.Future; 8 import com.framsticks.util.dispatching.Future; 9 10 import org.apache.commons.configuration.Configuration; 9 11 import org.apache.log4j.Logger; 10 12 … … 14 16 public class ServerInstance extends LocalInstance { 15 17 16 private final static Logger LOGGER= Logger.getLogger(ServerInstance.class.getName());18 private final static Logger log = Logger.getLogger(ServerInstance.class.getName()); 17 19 18 20 Entity hosted; 19 21 20 public ServerInstance(Parameters parameters) { 21 super(parameters); 22 } 22 public ServerInstance() { 23 } 23 24 24 25 26 27 28 29 25 @Override 26 protected void run() { 27 super.run(); 28 assert hosted != null; 29 hosted.start(); 30 } 30 31 31 32 protected void configure() throws Exception{33 super.configure();32 @Override 33 public void configure(Configuration config) { 34 super.configure(config); 34 35 35 Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this, null); 36 hosted = Program.configureEntity(p); 37 if (hosted == null) { 38 LOGGER.fatal("failed to create hosted entity"); 39 return; 40 } 41 hosted.configurePublic(); 42 root = new Node((CompositeParam)new ParamBuilder().setName("root").setId("root").setType("o" + hosted.getClass().getCanonicalName()).build(), hosted); 43 } 36 Configuration hostedConfig = config.subset("hosted.entity"); 37 hosted = Program.configureEntity(hostedConfig); 38 if (hosted == null) { 39 log.fatal("failed to create hosted entity"); 40 return; 41 } 42 hosted.setName("hosted"); 43 hosted.configure(hostedConfig); 44 root = new Node((CompositeParam)new ParamBuilder().setName("root").setId("root").setType("o" + hosted.getClass().getCanonicalName()).build(), hosted); 45 } 44 46 45 46 47 48 49 50 47 @Override 48 public FramsClass getInfoFromCache(String id) { 49 assert isActive(); 50 if (id == null) { 51 return null; 52 } 51 53 FramsClass cached = registry.getInfoFromCache(id); 52 54 if (cached != null) { 53 55 return cached; 54 55 56 ClassnativeClass = Class.forName(id);57 56 } 57 try { 58 Class<?> nativeClass = Class.forName(id); 59 FramsClass framsClass = new FramsClass.Constructor(nativeClass, id).getResult(); 58 60 59 60 61 62 63 61 registry.registerReflectedClass(null, id, nativeClass); 62 registry.putInfoIntoCache(framsClass); 63 return framsClass; 64 } catch (ClassNotFoundException ignored) { 65 } 64 66 65 66 67 return null; 68 } 67 69 68 69 70 70 @Override 71 protected void fetchInfo(Path path, Future<FramsClass> future) { 72 assert isActive(); 71 73 72 73 74 LOGGER.error("failed to create frams class for: " + path.getTop().getObject().getClass());75 76 77 78 74 FramsClass framsClass = getInfoFromCache(path.getTop().getObject().getClass().getCanonicalName()); 75 if (framsClass == null) { 76 log.error("failed to create frams class for: " + path.getTop().getObject().getClass()); 77 future.result(null, new Exception()); 78 return; 79 } 80 future.result(framsClass, null); 79 81 80 82 } 81 83 82 83 84 84 @Override 85 protected void tryRegisterOnChangeEvents(Path path) { 86 } 85 87 86 88 }
Note: See TracChangeset
for help on using the changeset viewer.