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

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

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

import javax.management.openmbean.TabularData;

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

import com.bagri.core.system.Library;
import com.bagri.core.xquery.api.XQCompiler;
import com.bagri.server.hazelcast.task.library.LibraryCreator;
import com.bagri.server.hazelcast.task.library.LibraryRemover;
import com.hazelcast.core.HazelcastInstance;

/**
 * @author Denis Sukhoroslov email: [email protected]
 *
 */
@ManagedResource(objectName="com.bagri.db:type=Management,name=LibraryManagement", 
	description="Extension Library Management MBean")
public class LibraryManagement extends EntityManagement {

	private XQCompiler xqComp;
	
    public LibraryManagement(HazelcastInstance hzInstance) {
    	super(hzInstance);
    }

	public void setXQCompiler(XQCompiler xqComp) {
		this.xqComp = xqComp;
		xqComp.setLibraries(entityCache.values());
	}
	
	@Override
	protected EntityManager createEntityManager(String libraryName) {
		LibraryManager mgr = new LibraryManager(hzInstance, libraryName);
		mgr.setEntityCache(entityCache);
		mgr.setXQCompiler(xqComp);
		return mgr;
	}
    
	@ManagedAttribute(description="Return registered Library names")
	public String[] getLibraryNames() {
		return getEntityNames();
	}

	@ManagedAttribute(description="Return registered Libraries")
	public TabularData getLibraries() {
		return getEntities("library", "Library definition");
    }
	
	@ManagedOperation(description="Creates a new Extension Library")
	@ManagedOperationParameters({
		@ManagedOperationParameter(name = "name", description = "Library name to create"),
		@ManagedOperationParameter(name = "fileName", description = "Library file (JAR), can be ommited"),
		@ManagedOperationParameter(name = "description", description = "Library description")})
	public boolean addLibrary(String name, String fileName, String description) {
		logger.trace("addLibrary.enter; name: {}", name);
		Library library = null;
		if (!entityCache.containsKey(name)) {
	    	Object result = entityCache.executeOnKey(name, new LibraryCreator(getCurrentUser(), fileName, description));
	    	library = (Library) result;
		}
		logger.trace("addLibrary.exit; library created: {}", library);
		return library != null;
	}
	
	@ManagedOperation(description="Removes an existing Extension Library")
	@ManagedOperationParameters({@ManagedOperationParameter(name = "name", description = "Library name to delete")})
	public boolean deleteLibrary(String name) {
		logger.trace("deleteLibrary.enter; name: {}", name);
		Library library = entityCache.get(name);
		if (library != null) {
	    	Object result = entityCache.executeOnKey(name, new LibraryRemover(library.getVersion(), getCurrentUser()));
	    	library = (Library) result;
		}
		logger.trace("deleteLibrary.exit; library deleted: {}", library);
		return library != null;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy