synchronized

you deploy Javascript to the server it doesn't seem to specify a standardised way of writing components so that I can concentrate on writing business software rather than solving technical issues while it is rumoured to be fast, studies such as this suggest it's half as slow as Java compared to Java, the node.js API and Javascript libraries available today are immature - think about things like sending email, ORM, etc. node.js has political problems because it relies on Google. If Google don't want to support Javascript on the server (their V8 engine is designed for Chrome, client side), and node.js needs a patch or development on V8 to handle a serverside issue, they might never get it. OK, like I have a chance to get a Java bug patched by Oracle ;-)

var net = require('net'); var server = net.createServer(function (socket) { socket.write("Echo server\r

"); socket.pipe(socket); }); server.listen(1337, "127.0.0.1");

TCPProtocol protocol = new TCPProtocol(){ public void handleRequest(ServerRequest request, ServerResponse response) { //echo what we just received try { response.write(request.getData()); } catch (IOException e) { e.printStackTrace(); } } }; Configuration config = new Configuration(1337, protocol); ServerFactory.createServer(config).listen();

handleRequest()

public void handleRequest(ServerRequest request, ServerResponse response) { String criterion = String.valueOf(request.getData()[0]); try{ //call through to the context for help - it //will call the handler for us. getContext().handleRequest(criterion, request, response); } catch (UnknownHandlerException e) { //send NOK to client because of unknown command response.write(new Packet(UNKNOWN_COMMAND).marshal()); } }

Packet

ServerRequest

ServerResponse

getContext().handleRequest(criterion, request, response)

@Handler(selector=VoipProtocol.LOGIN) public class VoipLoginHandler extends VoipHandler { public void service(VoipRequest request, VoipResponse response) throws IOException { String name = request.getPacket().getPayloadAsString(); Participant p = new Participant( name, response.getSocketChannel()); getProtocol().getModel().addParticipant(p); request.getKey().attach(p); //ACK String sessId = p.getSessId().getBytes(VoipProtocol.CHARSET); Packet packet = new Packet(sessId, VoipProtocol.LOGIN) response.write(packet); } }

service

Participant

attach(Object)

@Handler

@WebServlet

@WebServlet

VoipRequest

VoipResponse

ServerRequest

ServerResponse

service

service

@Handler

runAsync

@Handler(selector=VoipProtocol.QUIT) @RolesAllowed({"someRole", "someOtherRole"}) @TransactionManagement(TransactionManagementType.CONTAINER) public class VoipQuitHandler extends VoipHandler { @PersistenceContext(unitName="persistenceUnitName") private EntityManager em; . . . }

@RolesAllowed

@PersistenceContext

TCPServerRunner

VoipServerRunner

ListeningClient

SendingClient

SendingClient

runAsync

@Handler

Posted by Ant Kutschera on May 22, 2011 9:36:09 PM CEST #