⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processorfactory.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
字号:
package com.ufmobile.platform.mstreet.processor;

import java.util.Hashtable;
import java.util.ResourceBundle;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.hibernate.ejb.HibernatePersistence;

import com.ufmobile.platform.log.RunTimeLogger;

/**
 * 处理器工厂

 * com.ufmobile.platform.mstreet.processor.ProcessorFactory
 * Version:Ufmobile3.0
 * 2006-12-18
 * Copyright 用友移动商务
 */
public class ProcessorFactory {
	private static Hashtable<Integer, MOProcessor> moProcessorMap;
	private static Hashtable<Integer, MTProcessor> mtProcessorMap;
	private ProcessorFactory(){}
	/**
	 * 获取ProcessInterface实例
	 * @param type	处理器类型@see TYPE
	 * @return	ProcessInterface实例
	 */
	public synchronized static MOProcessor getMOInstance(int localId){
		MOProcessor ret = null;
		if(moProcessorMap == null){
			moProcessorMap = new Hashtable<Integer, MOProcessor>();
		}
		MOProcessor moProcessor = moProcessorMap.get(new Integer(localId));
		if(moProcessor == null){
			moProcessor = new MOProcessor(localId);		
			moProcessorMap.put(new Integer(localId), moProcessor);
			RunTimeLogger.info(ProcessorFactory.class, "start the id=" + localId + " MO thread");
		}
		ret = moProcessor;
		ret.run();
		return ret;
	}	
	public synchronized static MTProcessor getMTInstance(int localId){
		MTProcessor ret = null;
		if(mtProcessorMap == null){
			mtProcessorMap = new Hashtable<Integer, MTProcessor>();
		}
		MTProcessor mtProcessor = mtProcessorMap.get(new Integer(localId));
		if(mtProcessor == null){
			mtProcessor = new MTProcessor(localId);
			mtProcessorMap.put(new Integer(localId), mtProcessor);
			RunTimeLogger.info(ProcessorFactory.class, "start the id=" + localId + " MT thread");
		}
		ret = mtProcessor;
		ret.run();
		return ret;
	}	
	static ResourceBundle getResource(){
		ResourceBundle bundle = ResourceBundle.getBundle("config");
		return bundle;
	}
	private static Hashtable<Integer, EntityManagerFactory> entityManagerFactoryMap;
	static synchronized EntityManager getEntityManager(int localId){
		return getEntityManager(false, localId);
	}
	static synchronized EntityManager getEntityManager(boolean reset, int localId){
		if(entityManagerFactoryMap == null){
			entityManagerFactoryMap = new Hashtable<Integer, EntityManagerFactory>();
		}
		EntityManagerFactory entityManagerFactory = entityManagerFactoryMap.get(new Integer(localId));
		if(entityManagerFactory == null || reset){
			HibernatePersistence persistence = new HibernatePersistence();			
			entityManagerFactory = persistence.createEntityManagerFactory("smsUnit" + localId, null);	
			entityManagerFactoryMap.put(new Integer(localId), entityManagerFactory);
		}		
		return entityManagerFactory.createEntityManager();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -