org.usergrid.services.ServiceManagerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usergrid-services Show documentation
Show all versions of usergrid-services Show documentation
Service layer for Usergrid system.
/*******************************************************************************
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.usergrid.services;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.usergrid.batch.service.SchedulerService;
import org.usergrid.locking.LockManager;
import org.usergrid.persistence.EntityManager;
import org.usergrid.persistence.EntityManagerFactory;
public class ServiceManagerFactory implements ApplicationContextAware {
private ApplicationContext applicationContext;
private EntityManagerFactory emf;
private Properties properties;
private SchedulerService schedulerService;
private LockManager lockManager;
private List eventListeners;
private List collectionListeners;
public ServiceManagerFactory(EntityManagerFactory emf, Properties properties, SchedulerService schedulerService, LockManager lockManager) {
this.emf = emf;
this.properties = properties;
this.schedulerService = schedulerService;
this.lockManager = lockManager;
}
public ServiceManager getServiceManager(UUID applicationId) {
EntityManager em = null;
if (emf != null) {
em = emf.getEntityManager(applicationId);
}
ServiceManager sm = new ServiceManager();
sm.init(this, em, properties);
return sm;
//return applicationContext.getAutowireCapableBeanFactory()
// .createBean(ServiceManager.class).init(this, em, properties);
}
public List getExecutionEventListeners() {
return eventListeners;
}
public void setExecutionEventListeners(
List eventListeners) {
this.eventListeners = eventListeners;
}
public void notifyExecutionEventListeners(ServiceAction action,
ServiceRequest request, ServiceResults results,
ServicePayload payload) {
notifyExecutionEventListeners(new ServiceExecutionEvent(action,
request, results, payload));
}
public void notifyExecutionEventListeners(ServiceExecutionEvent event) {
if (eventListeners != null) {
for (ServiceExecutionEventListener listener : eventListeners) {
if (listener != null) {
listener.serviceExecuted(event);
}
}
}
}
public void notifyCollectionEventListeners(String path,
ServiceResults results) {
if (collectionListeners != null) {
for (ServiceCollectionEventListener listener : collectionListeners) {
if (listener != null) {
listener.collectionModified(path, results);
}
}
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
/**
* @return the applicationContext
*/
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public SchedulerService getSchedulerService() {
return schedulerService;
}
public LockManager getLockManager() {
return lockManager;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy