All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bagri.server.hazelcast.management.ModuleManager Maven / Gradle / Ivy

The newest version!
package com.bagri.server.hazelcast.management;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;

import com.bagri.core.api.BagriException;
import com.bagri.core.system.Module;
import com.bagri.core.xquery.api.XQCompiler;
import com.hazelcast.core.HazelcastInstance;

@ManagedResource(description="XQuery Module Manager MBean")
public class ModuleManager extends EntityManager { 

	private XQCompiler xqComp;
	//private IExecutorService execService;

	public ModuleManager() {
		super();
	}
    
	public ModuleManager(HazelcastInstance hzInstance, String moduleName) {
		super(hzInstance, moduleName);
	}

	public void setXQCompiler(XQCompiler xqComp) {
		this.xqComp = xqComp;
	}
	
	@ManagedOperation(description="Compiles registered Module")
	public boolean compileModule() {
		Module module = getEntity();
		try {
			xqComp.compileModule(module);
			return true;
		} catch (BagriException ex) {
			throw new RuntimeException(ex.getMessage());
		}
	}

	@ManagedOperation(description="Reloads registered Module from disk")
	public void refreshModule() {
		Set keys = new HashSet<>(1);
		keys.add(entityName);
		entityCache.loadAll(keys, true);
	}

	@ManagedOperation(description="Returns Module functions")
	public String[] getDeclaredFunctions() {
		Module module = getEntity();
		try {
			List list = xqComp.getModuleFunctions(module);
			return list.toArray(new String[list.size()]);
		} catch (BagriException ex) {
			throw new RuntimeException(ex.getMessage());
		}
	}
	
	@Override
	protected String getEntityType() {
		return "Module";
	}

	@ManagedOperation(description="Returns Module body")
	public String getBody() {
		return getEntity().getBody();
	}
	
	@ManagedAttribute(description="Returns Module description")
	public String getDescription() {
		return getEntity().getDescription();
	}

	@ManagedAttribute(description="Returns Module file name")
	public String getFileName() {
		return getEntity().getFileName();
	}
	
	public Module getModule() {
		return getEntity();
	}

	@ManagedAttribute(description="Returns registered Module name")
	public String getName() {
		return entityName;
	}

	@ManagedAttribute(description="Returns registered Module name")
	public String getNamespace() {
		return getEntity().getNamespace();
	}

	@ManagedAttribute(description="Returns Module compilation state")
	public String getState() {
		return xqComp.getModuleState(getEntity()) ? "valid" : "invalid";
	}

	@ManagedAttribute(description="Returns Module version")
	public int getVersion() {
		return super.getVersion();
	}
	
	@ManagedOperation(description="Updates Module body")
	public void setBody(String body) {
		// TODO: do this via EntryProcessor with locks etc.. 
		Module module = getEntity();
		module.setBody(body);
		flushEntity(module);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy