1 package com.jofti.plugin; 2 3 import java.util.Properties ; 4 5 import com.ibm.websphere.objectgrid.BackingMap; 6 import com.ibm.websphere.objectgrid.ObjectGrid; 7 import com.ibm.websphere.objectgrid.ObjectGridException; 8 import com.ibm.websphere.objectgrid.ObjectGridManager; 9 import com.ibm.websphere.objectgrid.ObjectGridManagerFactory; 10 import com.ibm.websphere.objectgrid.ObjectGridRuntimeException; 11 import com.ibm.websphere.objectgrid.TxID; 12 import com.ibm.websphere.objectgrid.plugins.LogSequence; 13 import com.ibm.websphere.objectgrid.plugins.index.MapIndexInfo; 14 import com.ibm.websphere.objectgrid.plugins.index.MapIndexPlugin; 15 import com.jofti.api.IndexManager; 16 import com.jofti.cache.adapter.ObjectGridListenerAdapter; 17 import com.jofti.cache.adapter.listener.ObjectGridEventListener; 18 import com.jofti.config.DefaultIndexConfig; 19 import com.jofti.exception.JoftiException; 20 import com.jofti.manager.IndexManagerImpl; 21 22 35 public class ObjectGridIndexPlugIn implements MapIndexPlugin{ 36 37 38 IndexManager manager = new IndexManagerImpl(); 39 DefaultIndexConfig config = new DefaultIndexConfig(); 40 private boolean started = false; 41 private String configFile =null; 42 private String backingMapName =null; 43 private String gridName =null; 44 45 ObjectGridEventListener listener =null; 46 47 48 public ObjectGridIndexPlugIn(){ 49 50 config = new DefaultIndexConfig(); 51 Properties props = new Properties (); 52 props.put("plugin", "true"); 53 config.setAdapterProperties(props); 54 config.setCacheAdapter("com.jofti.cache.adapter.ObjectGridListenerAdapter"); 55 56 } 57 58 public void setName(String name){ 59 config.setName(name); 60 61 } 62 63 public void setConfigFile(String fileName){ 64 this.configFile = fileName; 65 } 66 67 public void setGridName(String name){ 68 this.gridName =name; 69 } 70 71 public void setBackingMapName(String name){ 72 this.backingMapName = name; 73 } 74 private synchronized void init(String objectGridName, String mapName) throws JoftiException{ 75 76 if (!started){ 77 System.out.println("initialising"); 78 ObjectGridManager oGridManager= 79 ObjectGridManagerFactory.getObjectGridManager(); 80 ObjectGrid grid = oGridManager.getObjectGrid(objectGridName); 81 82 if (grid == null){ 83 throw new JoftiException("Unable to find grid:"+objectGridName); 84 } 85 BackingMap map = grid.getMap(mapName); 86 87 if (map ==null){ 88 throw new JoftiException("Unable to find map:"+mapName); 89 } 90 if (config.getName() == null){ 91 throw new JoftiException("Index name cannot be null"); 92 } 93 ObjectGridListenerAdapter adapter =null; 94 if (configFile != null){ 95 adapter = (ObjectGridListenerAdapter) manager.addIndex(config,map,configFile ); 96 }else{ 97 adapter = (ObjectGridListenerAdapter)manager.addIndex(config, map); 98 } 99 100 listener = adapter.getEventListener(); 101 started =true; 102 } 103 } 104 105 108 public void doBatchUpdate(TxID txid, LogSequence logsequence) throws ObjectGridRuntimeException { 109 110 try { 111 init(logsequence.getObjectGridName(), logsequence.getMapName()); 112 }catch (JoftiException e){ 113 throw new ObjectGridRuntimeException(e); 114 } 115 listener.doBatchUpdate(txid, logsequence); 116 117 } 118 119 122 public Object getIndexProxy(MapIndexInfo mapindexinfo) { 123 124 if (!started && (gridName == null || backingMapName ==null)){ 125 throw new RuntimeException ("gridname and backingMap name must be set in Plug-In config"); 126 } 127 128 try { 129 init(gridName, backingMapName); 130 }catch (JoftiException e){ 131 throw new ObjectGridRuntimeException(e); 132 } 133 return listener.getIndexProxy(mapindexinfo); 134 } 135 136 public String getName() { 137 return config.getName(); 138 } 139 140 public void setAttributeName(String s) { 141 } 143 144 public void undoBatchUpdate(TxID txid, LogSequence logsequence) throws ObjectGridException { 145 listener.undoBatchUpdate(txid, logsequence); 146 147 } 148 149 } 150 | Popular Tags |