# HG changeset patch # User Andrew Azores # Date 1507732600 14400 # Node ID 3757ec9994fa77e29b54344c9767aa37d057959d # Parent e905e459ea483f15abfe9c0f7088d4e54cc2d69f Add caching to byteman service Cache JVM mainClass and listen port. Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025182.html Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025354.html diff -r e905e459ea48 -r 3757ec9994fa src/app/components/jvm-info/byteman/byteman.service.js --- a/src/app/components/jvm-info/byteman/byteman.service.js Wed Oct 11 09:39:05 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.service.js Wed Oct 11 10:36:40 2017 -0400 @@ -42,6 +42,9 @@ this._http = $http; this._gatewayUrl = gatewayUrl; this._cmdChan = commandChannelService; + + this._mainClassCache = new Map(); + this._listenPortCache = new Map(); } getLoadedRules (jvmId) { @@ -62,7 +65,14 @@ } getJvmMainClass (systemId, jvmId) { - return this._getJvmInfo(systemId, jvmId).then(res => res.mainClass); + if (this._mainClassCache.has(jvmId)) { + return this._q(resolve => resolve(this._mainClassCache.get(jvmId))); + } + return this._getJvmInfo(systemId, jvmId).then(res => { + let mainclass = res.mainClass; + this._mainClassCache.set(jvmId, mainclass); + return mainclass; + }); } getMetrics (jvmId, oldestLimit) { @@ -160,11 +170,16 @@ } _getListenPort (jvmId) { + if (this._listenPortCache.has(jvmId)) { + return this._q(resolve => resolve(this._listenPortCache.get(jvmId))); + } return this._getBytemanStatus(jvmId).then(res => { if (!res) { return INITIAL_LISTEN_PORT; } - return res.listenPort; + let port = res.listenPort; + this._listenPortCache.set(jvmId, port); + return port; }); } } diff -r e905e459ea48 -r 3757ec9994fa src/app/components/jvm-info/byteman/byteman.service.spec.js --- a/src/app/components/jvm-info/byteman/byteman.service.spec.js Wed Oct 11 09:39:05 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.service.spec.js Wed Oct 11 10:36:40 2017 -0400 @@ -319,5 +319,58 @@ }); }); + describe('caching', () => { + it('should cache jvm mainClass', done => { + let response = { + response: [ + { + mainClass: 'com.example.FooClass' + } + ] + }; + let requestHandler = httpBackend.expectGET('http://example.com:1234/jvms/0.0.1/systems/foo-systemId/jvms/foo-jvmId') + .respond(() => { + requestHandler.respond(500); + return [200, response]; + }); + svc.getJvmMainClass('foo-systemId', 'foo-jvmId').then(res => { + res.should.equal(response.response[0].mainClass); + httpBackend.resetExpectations(); + + svc.getJvmMainClass('foo-systemId', 'foo-jvmId').then(res => { + res.should.equal(response.response[0].mainClass); + done(); + }); + }); + httpBackend.flush(); + scope.$apply(); + }); + + it('should cache jvm listenport', done => { + let response = { + response: [ + { + listenPort: 9999 + } + ] + }; + let requestHandler = httpBackend.expectGET('http://example.com:1234/jvm-byteman/0.0.1/status/jvms/foo-jvmId') + .respond(() => { + requestHandler.respond(500); + return [200, response]; + }); + svc._getListenPort('foo-jvmId').then(res => { + res.should.equal(response.response[0].listenPort); + httpBackend.resetExpectations(); + + svc._getListenPort('foo-jvmId').then(res => { + res.should.equal(response.response[0].listenPort); + done(); + }); + }); + httpBackend.flush(); + scope.$apply(); + }); + }); + }); -