Avatar 2.0

Click here to load reader

  • date post

    02-Jul-2015
  • Category

    Internet

  • view

    884
  • download

    0

Embed Size (px)

description

Presented at J-Fall (Nov. 2014)

Transcript of Avatar 2.0

  • 1. DavidDelabassee(@delabassee)OracleCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.|Avatar2.0J-Fall20141

2. SafeHarborStatementThefollowingisintendedtooutlineourgeneralproductdirection.Itisintendedforinformationpurposesonly,andmaynotbeincorporatedintoanycontract.Itisnotacommitmenttodeliveranymaterial,code,orfunctionality,andshouldnotberelieduponinmakingpurchasingdecisions.Thedevelopment,release,andtimingofanyfeaturesorfunctionalitydescribedforOraclesproductsremainsatthesolediscretionofOracle.Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.2 3. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.3JavaEEJavaPlatformJavaontheServerSideAgenda 4. JavaScriptCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.4JavaEEJavaPlatformJavaontheServerSideAgenda 5. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.Node.js Server-sideJavaScriptbasedonChromev8engine Createdin2009,OpenSource DesignedforscalableInternetapplications Meltingpotcommunity Java,.NET,Browser,PHP,etc,experience NodePackagedModules Veryactive,with+98,000modules(YMMV)5ServerSideJavaScript 6. Node.jsProgrammingModel Multi-threadingCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.ishard Thousandsofconcurrentconnections Dealwithdeadlocksandraceconditions BlockingonI/Oisbad EventLoop ReactiveModel Non-blockingI/Ocalls Applicationcodeexecutesinasinglethread6EventClients LoopNon-blockingWorker 7. Node.jsProgrammingModelCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.7var http = require("http");!!http.createServer( ).listen(80); 8. Node.jsProgrammingModelCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.8var http = require("http");!!http.createServer(function(request, response) {!! response.writeHead(200, {"Content-type": "text/plain"});!! response.write("Hello World";)!! response.end();!}).listen(80); 9. 64,531,5Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.Nashorn! BundledwithJava7and8 ECMAScript5.1compatibility Performance(vsRhino) JavaInteroperability90crypto earley-boyer mandreel pdas regexp splayrhinonashornjdk8nashornjdk9JavaScriptEngine 10. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.NashornQuickDemo10 11. ScalingServer-SideJavaScriptCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.11 12. WhatIfIminaJavaShop?Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved. JavaDeveloperInvestments In-houseJava-basedframeworks 3rdpartycommercialand/oropensourcelibraries LotsofexperiencewithJavadevelopment InvestmentinJavainfrastructure JavaEEapplicationservers JMX-basedmonitoringandmanagement Establisheddatacenterprocessesandbestpractices WeareaJavacompany,orWealreadydoJavaand.NET12 13. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.ProjectAvatar13BridgingthegapAvatarNodeontheJVM!ThousandsofNodelibraries!ThousandsofJavalibrariesJavaEEInteroperability!LeverageExistingInfrastructure!BuildEnterpriseApplicationsinJavaScript! 14. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.Avatar2.0 95%NodecompatibilityprovidedbyAvatar.js UsessameCportabilitylibrariesasNode.js libuv,http-parser NoChromev8nativeAPIs! Runpopularpackages Express,async,commander,etc.14 15. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.Avatar2.0 EnterpriseFeatures Advancedmultithreading Statesharing AvatarPersistence JavaEEInteroperability(EJB,JMS)15 16. AvatarProcessApplication JavaScript Modules & Java JarsBundled Third-Party JavaScript ModulesAvatar API ModulesWLS T3 thin clientEclipseLink, NoSQLMBeansAvatarFlight Recorder ProbesApplicationJavaScript&JavaJavaScriptcodeCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.16Avatar2.0ArchitectureREST/WS/SSEJVMCore Node ModulesNashorn & JRE 8MissionControlMgmt Plugin Admin AgentEJB/JMS WebLogicData Databaselibuv + JNI bindingsJavacodePlatformspecificnativecodeOptionalProcessesCoherence State Coherence 17. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.17Nashorn-UsingJava8withinaNodeappvar http = require("http");!var list = new java.util.ArrayList();!!list.add("Blue"); list.add(Green"); list.add("Yellow");!list.add("Red"); list.add("Dark Red"); list.add("Light Red);!!http.createServer(function(request, response) {!response.writeHead(200, {"Content-Type": "application/json"});! !var count = list.parallelStream()!.filter(function(t) { return t.match('Red') } )!.count();! !response.end({'reds': count});!}).listen(8080); 18. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.AvatarMultithreading MultipleinstancesofanapplicationinsingleJVMprocess EachinstancehasitsowneventloopthreadandJavaScriptcontext Sharedsocketseveryinstancelistensonthesameport OptionalcoordinationviaJavaScriptstatesharingAPIs MessagingAPI MapAPI Candynamicallycreatebackgroundthreadsaswell18TakingadvantageofthemultithreadedJVM 19. AvatarApplicationScalingCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.19Apictureisworthathousandthreads 20. CreatingNewEventThreadsCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.20!var threads = require('avatar/threads');!var createBallThread = function(ballInfo) {!! var deferred = when.defer();!! var eventThread = threads.newEventThread("BouncingBallThread", !! ! __dirname + "/ball.js", [!! ! ! "color=" + ballInfo.color,!! ! ! "gravity=" + ballInfo.gravity,!! ! ! "rowid=" + ballInfo.id_!!! ! ]);!! eventThread.start(function (event, error) {!! ! switch(event) {!! ! ! case "started":!! ! ! ! console.log("Thread ", eventThread.thread.index(), "Started");!! ! ! ! ballInfo.id = eventThread.thread.index();! 21. AvatarSharedStateFrameworkCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved. MessageBus Publish/subscribemessagepassing SharedState SimplemapAPI Application-scopedinstance Session-scopedinstance Named Leased,withconfigurabletimeout Avatarprovidesrequiredserialization,concurrencycontrol,andcaching21Lightweightinter-threadcommunication 22. MessageBus(Subscribe)Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.22bus.on("kill", function (id) {!if (_interval && _id && (_id.toString() === id.toString())) {!clearInterval(_interval);!process.exit();!}!});!!bus.subscribe("argsUpdate", function (data) {!if (data.id === app.threadIndex) {!gravity = data.gravity;!}!}); 23. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.23MessageBus(Publish)_interval = setInterval(function () {!var msg = {!id: _id, !color: app.args.color,!heartbeat: heartbeat++, !!};! !msg.message = "Thread " + app.threadIndex + " | Heartbeat: " +!heartbeat + " | Gravity: " + gravity;! !bus.publish("messages", msg);! !}, 2000); 24. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved. SupportsRelational&NoSQLdatabases SimilartoSequelize,JugglingDB,etc LeveragesEclipseLinkJPAProvider Leveragesmature,featurerichJavaecosystem ToolingtogenerateJavaScriptmodelforexistingdatabaseschema 2ndlevelJPAcache(TopLinkGrid) OracleRACconnectionpooling,etc.24AvatarPersistenceFrameworkJavaScriptAPI 25. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.25AvatarPersistence(Model)var avatar = require("avatar");!var model = require("avatar/model");! !var store = model.newStore(config.db.name, {!database: config.db.database,!username: config.db.username,!properties: { "eclipselink.logging.level": INFO }!});! !var BallModel = model.newModel("Ball", {!"color": "string",!"gravity": "number"!});! !store.bind(BallModel); 26. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.26AvatarPersistence(Model)var avatar = require("avatar");!var model = require("avatar/model");! !var store = model.newStore(config.db.name, {!database: config.db.database,!username: config.db.username,!properties: { "eclipselink.logging.level": INFO }!});! !var BallModel = model.newModel("Ball", {!"color": "string",!"gravity": "number"!});! !store.bind(BallModel); 27. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.27AvatarPersistencereturn {!! getThreads: function() {!! ! return BallModel.getAll();!! },!! !! createThread: function(thread) {!! ! return BallModel.create(aBall);!! },!! !! deleteThread: function(id) {!! ! return BallModel.delete(id);!! },!! !! updateThread: function(data) {!! ! var deferred = when.defer();!! ! BallModel.get(data.id_).then(function(row) {!! ! row.gravity = parseInt(data.gravity);!! ! BallModel.put(row).then(function(updatedRow) { 28. model.jsheartbeat gravity heartbeat heartbeat MessageBusexpress.js ws.js avatar.jsCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved.28Browser main.js ball.js ball.js ball.js...ball.jsnewEventThread(ball.js)RESTWebSocketAvatarProcessDatabaseDemo 29. AdditionalFeaturesandPotential ExpandJavaMissionControl/FlightRecordersupportCopyright2014,Oracleand/oritsaffiliates.Allrightsreserved. RemoteEJBandJMSsupport UsingWebLogict3thinclient Automaticallyreloadapplicationonfilechange(developmentfeature) Workinprogress Coherence(JCache)integrationforcross-JVMstatesharing ManageusingWebLogicand/orOracleEnterpriseManager29 30. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.Next CheckProjectAvatar(akaAvatar1.0)- http://avatar.java.net WeplantoopensourceAvatar2.0soon Weneedyourfeedback!! ThankYou!30 31. Copyright2014,Oracleand/oritsaffiliates.Allrightsreserved.31