Project

General

Profile

« Previous | Next » 

Revision 6401

Modify HazelcastService to read configuration information from an on-disk file (not from a jar file). Added init() to start up the service (was calling doRefresh() before. We still need to decide if this is a refreshable service.

View differences:

src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.dataone.hazelcast;
28 28

  
29
import java.io.File;
30

  
29 31
import org.apache.log4j.Logger;
30 32
import org.dataone.service.types.v1.Identifier;
31 33
import org.dataone.service.types.v1.SystemMetadata;
32 34

  
35
import com.hazelcast.config.Config;
33 36
import com.hazelcast.core.Hazelcast;
37
import com.hazelcast.core.HazelcastInstance;
34 38
import com.hazelcast.core.IMap;
35 39
import com.hazelcast.core.InstanceEvent;
36 40
import com.hazelcast.core.InstanceListener;
37 41

  
42
import edu.ucsb.nceas.metacat.properties.PropertyService;
38 43
import edu.ucsb.nceas.metacat.shared.BaseService;
39 44
import edu.ucsb.nceas.metacat.shared.ServiceException;
40

  
45
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
41 46
/**
42 47
 * The Hazelcast service enables Metacat as a Hazelcast cluster member
43 48
 */
......
48 53
  private static Logger logMetacat = Logger.getLogger(HazelcastService.class);
49 54
  
50 55
  /* The singleton instance of the hazelcast service */
51
  private static HazelcastService hazelcastService = null;
56
  private static HazelcastService hzService = null;
52 57
  
53
  /*The distributed DataONE system metadata map*/
54
  private IMap<Identifier, SystemMetadata> systemMetadata;
58
  /* The Hazelcast instance that is a cluster member */
59
  private HazelcastInstance hzMember;
55 60
  
56
  /* the name of the system metadata map in hazelcast */
57
  private String systemMetadataMap = "hzSystemMetadata";
61
  /* The Hazelcast configuration */
62
  private Config hzConfig;
58 63
  
59 64
  /*
60 65
   * Constructor: Creates an instance of the hazelcast service. Since
......
66 71
    _serviceName="HazelcastService";
67 72
    
68 73
    try {
69
      doRefresh();
74
      init();
70 75
      
71 76
    } catch (ServiceException se) {
72 77
      logMetacat.debug("There was a problem creating the HazelcastService. " +
......
84 89
   */
85 90
  public static HazelcastService getInstance(){
86 91
    
87
    if ( hazelcastService == null ) {
92
    if ( hzService == null ) {
88 93
      
89
      hazelcastService = new HazelcastService();
94
      hzService = new HazelcastService();
90 95
      
91 96
    }
92
    return hazelcastService;
97
    return hzService;
93 98
  }
94 99
  
95 100
  /**
96
   * Refreshes the Hazelcast service
101
   * Initializes the Hazelcast service
97 102
   */
98
  public void doRefresh() throws ServiceException {
103
  public void init() throws ServiceException {
99 104
    
100 105
    logMetacat.debug("HazelcastService.doRefresh() called.");
101 106
    
102
    this.systemMetadata = Hazelcast.getMap(this.systemMetadataMap);
107
    try {
108
	    File hzConfigFile =
109
	    	new File(PropertyService.getProperty("dataone.hazelcast.configFilePath"));
110
	    hzConfig = new Config();
111
	    hzConfig.setConfigurationFile(hzConfigFile);
112
	    hzMember = Hazelcast.init(hzConfig);
113

  
114
    } catch (PropertyNotFoundException e) {
115
    	String msg = "Couldn't find the Hazelcast configuration file.";
116
	    logMetacat.error(msg);
117
    	throw new ServiceException(msg);
103 118
    
119
    } catch (IllegalStateException e) {
120

  
121
    	String msg = "This instance of Hazelcast has already been created.";
122
	    logMetacat.error(msg);
123
    	throw new ServiceException(msg);
124

  
125
    }
126
    
104 127
    return;
105 128
    
106 129
  }
......
111 134
   * @return refreshable - the boolean refreshable status
112 135
   */
113 136
  public boolean refreshable() {
114
    return false; //right?
137
    // TODO: Determine the consequences of restarting the Hazelcast instance
138
  	// Set this to true if it's okay to drop from the cluster, lose the maps,
139
  	// and start back up again
140
  	return false;
115 141
    
116 142
  }
117 143
  
......
144 170
	  
145 171
  }
146 172

  
173
	
174
	/**
175
	 * Refresh the Hazelcast service by restarting it
176
	 */
177
	@Override
178
  protected void doRefresh() throws ServiceException {
179

  
180
		// TODO: verify that the correct config file is still used
181
    Hazelcast.getLifecycleService().restart();
182
	  
183
  }
184

  
147 185
}

Also available in: Unified diff