Project

General

Profile

Revision 6398

Adding a HazelcastService for Metacat to enable Metacat as a Hazelcast cluster member in DataONE. This will require the hazelcast.xml configuration file used for the DataONE cluster to be on the Metacat classpath.

View differences:

src/edu/ucsb/nceas/metacat/service/HazelcastService.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: Implements a service for managing a Hazelcast cluster member
4
 *  Copyright: 2011 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Christopher Jones
7
 * 
8
 *   '$Author$'
9
 *     '$Date$'
10
 * '$Revision$'
11
 *
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */
26

  
27
package edu.ucsb.nceas.metacat.service;
28

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

  
33
import com.hazelcast.core.Hazelcast;
34
import com.hazelcast.core.IMap;
35
import com.hazelcast.core.InstanceEvent;
36
import com.hazelcast.core.InstanceListener;
37

  
38
import edu.ucsb.nceas.metacat.shared.BaseService;
39
import edu.ucsb.nceas.metacat.shared.ServiceException;
40

  
41
/**
42
 * The Hazelcast service enables Metacat as a Hazelcast cluster member
43
 */
44
public class HazelcastService extends BaseService
45
  implements InstanceListener {
46
  
47
  /* The instance of the logging class */
48
  private static Logger logMetacat = Logger.getLogger(HazelcastService.class);
49
  
50
  /* The singleton instance of the hazelcast service */
51
  private static HazelcastService hazelcastService = null;
52
  
53
  /*The distributed DataONE system metadata map*/
54
  private IMap<Identifier, SystemMetadata> systemMetadata;
55
  
56
  /* the name of the system metadata map in hazelcast */
57
  private String systemMetadataMap = "hzSystemMetadata";
58
  
59
  /*
60
   * Constructor: Creates an instance of the hazelcast service. Since
61
   * this uses a singleton pattern, use getInstance() to gain the instance.
62
   */
63
  private HazelcastService() {
64
    
65
    super();
66
    _serviceName="HazelcastService";
67
    
68
    try {
69
      doRefresh();
70
      
71
    } catch (ServiceException se) {
72
      logMetacat.debug("There was a problem creating the HazelcastService. " +
73
                       "The error message was: " + se.getMessage());
74
      
75
    }
76
    
77
  }
78
  
79
  /**
80
   *  Get the instance of the HazelcastService that has been instantiated,
81
   *  or instantiate one if it has not been already.
82
   *
83
   * @return hazelcastService - The instance of the hazelcast service
84
   */
85
  public static HazelcastService getInstance(){
86
    
87
    if ( hazelcastService == null ) {
88
      
89
      hazelcastService = new HazelcastService();
90
      
91
    }
92
    return hazelcastService;
93
  }
94
  
95
  /**
96
   * Refreshes the Hazelcast service
97
   */
98
  public void doRefresh() throws ServiceException {
99
    
100
    logMetacat.debug("HazelcastService.doRefresh() called.");
101
    
102
    this.systemMetadata = Hazelcast.getMap(this.systemMetadataMap);
103
    
104
    return;
105
    
106
  }
107
  
108
  /**
109
   * Indicate whether or not this service is refreshable.
110
   *
111
   * @return refreshable - the boolean refreshable status
112
   */
113
  public boolean refreshable() {
114
    return false; //right?
115
    
116
  }
117
  
118
  /**
119
   * Stop the HazelcastService. When stopped, the service will no longer
120
   * respond to requests.
121
   */
122
  public void stop() throws ServiceException {
123
    
124
    Hazelcast.getLifecycleService().shutdown();
125
    
126
  }
127

  
128
  /**
129
   * Listen for new Hazelcast member events
130
   */
131
	@Override
132
  public void instanceCreated(InstanceEvent event) {
133
		logMetacat.info("New Hazelcast instance created: " +
134
			event.getInstance().getId() + ", " +
135
			event.getInstance().getInstanceType());
136
		
137
  }
138

  
139
	@Override
140
  public void instanceDestroyed(InstanceEvent event) {
141
		logMetacat.info("Hazelcast instance removed: " +
142
				event.getInstance().getId() + ", " +
143
				event.getInstance().getInstanceType());
144
	  
145
  }
146

  
147
}
0 148

  

Also available in: Unified diff