Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared): jolokia instance is created every time getJolokia() is invoked #616

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hawtio/src/plugins/rbac/rbac-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RBACService implements IRBACService {
this.aclMBean = undefined
}

async getACLMBean(): Promise<string> {
getACLMBean(): Promise<string> {
if (this.aclMBean) {
return this.aclMBean
}
Expand Down
40 changes: 22 additions & 18 deletions packages/hawtio/src/plugins/shared/jolokia-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,28 @@ class JolokiaService implements IJolokiaService {
return this.jolokiaUrl
}

async getJolokia(): Promise<Jolokia> {
getJolokia(): Promise<Jolokia> {
if (this.jolokia) {
return this.jolokia
}

// Initialising Jolokia instance

const jolokia = await this.createJolokia()
// Checking versions
jolokia.version(
onVersionSuccessAndError(
version => {
log.info('Jolokia version:', { client: jolokia.CLIENT_VERSION, agent: version.agent })
},
error => log.error('Failed to fetch Jolokia version:', error),
),
)
// Start Jolokia
const updateRate = this.loadUpdateRate()
jolokia.start(updateRate)
log.info('Jolokia started with update rate =', updateRate)
return jolokia
this.jolokia = this.createJolokia(jolokia => {
// Checking versions
jolokia.version(
onVersionSuccessAndError(
version => {
log.info('Jolokia version:', { client: jolokia.CLIENT_VERSION, agent: version.agent })
},
error => log.error('Failed to fetch Jolokia version:', error),
),
)
// Start Jolokia
const updateRate = this.loadUpdateRate()
jolokia.start(updateRate)
log.info('Jolokia started with update rate =', updateRate)
})
return this.jolokia
}

private async initJolokiaUrl(): Promise<string | null> {
Expand Down Expand Up @@ -212,7 +212,7 @@ class JolokiaService implements IJolokiaService {
})
}

private async createJolokia(): Promise<Jolokia> {
private async createJolokia(postCreate?: (jolokia: Jolokia) => void): Promise<Jolokia> {
const jolokiaUrl = await this.getJolokiaUrl()
if (!jolokiaUrl) {
log.debug('Use dummy Jolokia')
Expand All @@ -237,6 +237,10 @@ class JolokiaService implements IJolokiaService {
// let's check if we can call faster jolokia.list()
await this.checkListOptimisation(jolokia)

// Run any post-create processing that should be done before the resolved
// Jolokia is returned
postCreate?.(jolokia)

return jolokia
}

Expand Down
2 changes: 1 addition & 1 deletion packages/hawtio/src/plugins/shared/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Workspace implements IWorkspace {
eventService.refresh()
}

async getTree(): Promise<MBeanTree> {
getTree(): Promise<MBeanTree> {
if (this.tree) {
return this.tree
}
Expand Down
Loading