1 29 30 package com.caucho.server.cluster; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.log.Log; 34 import com.caucho.naming.Jndi; 35 import com.caucho.util.L10N; 36 37 import javax.annotation.PostConstruct; 38 import java.util.logging.Level ; 39 import java.util.logging.Logger ; 40 41 44 public class PersistentStoreConfig { 45 static protected final Logger log = Log.open(PersistentStoreConfig.class); 46 static final L10N L = new L10N(PersistentStoreConfig.class); 47 48 private String _name = "caucho/persistent-store"; 49 50 private StoreManager _store; 51 52 55 public void setJndiName(String name) 56 { 57 _name = name; 58 } 59 60 63 public void setType(String type) 64 throws ConfigException 65 { 66 Cluster cluster = Cluster.getLocal(); 67 68 if (type.equals("jdbc")) { 69 try { 70 Class cl = Class.forName("com.caucho.server.cluster.JdbcStore"); 71 72 _store = (StoreManager) cl.newInstance(); 73 74 if (cluster != null) 75 cluster.setStore(_store); 76 } catch (Throwable e) { 77 log.log(Level.FINER, e.toString(), e); 78 } 79 80 if (_store == null) 81 throw new ConfigException(L.l("'{0}' persistent sessions are available in Resin Professional. See http://www.caucho.com for information and licensing.", 82 type)); 83 } 84 else if (type.equals("file")) 85 _store = new FileStore(); 86 else if (type.equals("cluster") || type.equals("tcp")) { 87 if (cluster == null) 88 throw new ConfigException(L.l("Cluster store needs a defined <cluster>. Use 'file' for single-machine persistence.")); 89 90 try { 91 Class cl = Class.forName("com.caucho.server.cluster.ClusterStore"); 92 93 _store = (StoreManager) cl.newInstance(); 94 95 if (cluster != null) 96 cluster.setStore(_store); 97 } catch (Throwable e) { 98 log.log(Level.FINER, e.toString(), e); 99 } 100 101 if (_store == null) 102 throw new ConfigException(L.l("'{0}' persistent sessions are available in Resin Professional. See http://www.caucho.com for information and licensing.", 103 type)); 104 } 105 106 if (_store == null) 107 throw new ConfigException(L.l("{0} is an unknown persistent-store type. Only 'jdbc', 'file', and 'tcp' are allowed.", 108 type)); 109 } 110 111 public StoreManager createInit() 112 { 113 return _store; 114 } 115 116 @PostConstruct 117 public void init() 118 throws Exception 119 { 120 if (_store == null) 121 throw new ConfigException(L.l("type is a required attribute of persistent-store")); 122 123 _store.init(); 124 125 if (_name.startsWith("java:comp")) 126 Jndi.bindDeep(_name, _store); 127 else 128 Jndi.bindDeep("java:comp/env/" + _name, _store); 129 } 130 } 131 | Popular Tags |