mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
36614: ALF-13822: Renamed JGroupsKeepAliveHeartbeatReceiver. 36615: ALF-13822: renamed JGroupsKeepAliveHeartbeatSender. 36616: ALF-13822: renamed JGroupsRMICacheManagerPeerProvider. 36626: ALF-13822: renamed package from jgroups to cluster. 36642: ALF-13822: remove jgroupsChannelFactory from bootstrap-context.xml, exchange for Hazelcast. 36648: ALF-13822: remove jgroups references from RMICacheManagerPeerProvider. 36649: ALF-13822: Replaced jgroups with hazelcast in ehcache testing context. 36650: ALF-13822: Renamed ehcache test context and config so that jgroups not in name. 36651: ALF-13822: renamed jgroups package to ehcache. 36652: ALF-13822: Fix broken test from XML file renames. 36653: ALF-13822: rename file so that it doesn't have jgroups in the name. 36667: ALF-13822: removed some commented out jgroups code. 36679: ALF-13822: reimplemented membership change logging for KeepAliveHeartbeatReceiver. 36680: ALF-13822: remove redundant JGroups properties from clusterPropertySetter 36681: ALF-13822: remove redundant properties from repository.properties. 36682: ALF-13822: remove jgroups configuration files. 36683: ALF-13822: remove jgroups messenger abstraction classes. 36684: ALF-13822: removed jgroups test XML 36685: ALF-13822: remove AlfrescoJGroupsChannelFactory. 36686: ALF-13822: updated comment to include word hazelcast rather than jgroups. 36687: ALF-13822: removed jgroups from comment 36688: ALF-13822: removed jgroups from comment 36689: ALF-13822: removed jgroups comment as no longer relavent 36697: ALF-13822: removed jgroups from ant build files. 36704: ALF-13822: removed jgroups libraries. 36707: ALF-13822: removed jgroups source zip. 36708: ALF-13822: removed jgroups form installer license file. 36710: ALF-13822: removed jgroups lib from 3rd-party eclipse project's classpath. 36731: ALF-13822: removed mentions of jgroups from JLAN. 36761: ALF-13822: fixed hazelcast TCP config - removed ever-present loopback interface. 36762: ALF-13822: improved logging of KeepAliveHeartbeatReceiver and added toString() for HazelcastMessenger. 36990: ALF-13822: fixed AWS placeholder properties and added interface binding properties. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@37008 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
118 lines
4.0 KiB
Java
118 lines
4.0 KiB
Java
/*
|
|
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.alfresco.repo.cluster;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Set;
|
|
|
|
import com.hazelcast.core.HazelcastInstance;
|
|
import com.hazelcast.core.ITopic;
|
|
import com.hazelcast.core.Member;
|
|
import com.hazelcast.core.MembershipEvent;
|
|
import com.hazelcast.core.MembershipListener;
|
|
|
|
/**
|
|
* Hazelcast-based implementation of the {@link MessengerFactory} interface.
|
|
* The factory must be configured with a {@link HazelcastInstance} - which
|
|
* is the underlying factory for {@link ITopic} creation.
|
|
*
|
|
* @author Matt Ward
|
|
*/
|
|
public class HazelcastMessengerFactory implements MessengerFactory
|
|
{
|
|
private HazelcastInstanceFactory hazelcastInstanceFactory;
|
|
|
|
@Override
|
|
public <T extends Serializable> Messenger<T> createMessenger(String appRegion)
|
|
{
|
|
return createMessenger(appRegion, false);
|
|
}
|
|
|
|
@Override
|
|
public <T extends Serializable> Messenger<T> createMessenger(String appRegion, boolean acceptLocalMessages)
|
|
{
|
|
if (!isClusterActive())
|
|
{
|
|
return new NullMessenger<T>();
|
|
}
|
|
// Clustering is enabled, create a messenger.
|
|
HazelcastInstance hazelcast = hazelcastInstanceFactory.getInstance();
|
|
ITopic<T> topic = hazelcast.getTopic(appRegion);
|
|
String address = hazelcast.getCluster().getLocalMember().getInetSocketAddress().toString();
|
|
return new HazelcastMessenger<T>(topic, address);
|
|
}
|
|
|
|
/**
|
|
* Provide the messenger factory with a means to obtain a HazelcastInstance.
|
|
*
|
|
* @param hazelcastInstanceFactory
|
|
*/
|
|
public void setHazelcastInstanceFactory(HazelcastInstanceFactory hazelcastInstanceFactory)
|
|
{
|
|
this.hazelcastInstanceFactory = hazelcastInstanceFactory;
|
|
}
|
|
|
|
@Override
|
|
public boolean isClusterActive()
|
|
{
|
|
return hazelcastInstanceFactory.isClusteringEnabled();
|
|
}
|
|
|
|
@Override
|
|
public void addMembershipListener(final ClusterMembershipListener listener)
|
|
{
|
|
if (isClusterActive())
|
|
{
|
|
HazelcastInstance hazelcast = hazelcastInstanceFactory.getInstance();
|
|
hazelcast.getCluster().addMembershipListener(new MembershipListener()
|
|
{
|
|
@Override
|
|
public void memberRemoved(MembershipEvent e)
|
|
{
|
|
listener.memberLeft(member(e), cluster(e));
|
|
}
|
|
|
|
@Override
|
|
public void memberAdded(MembershipEvent e)
|
|
{
|
|
listener.memberJoined(member(e), cluster(e));
|
|
}
|
|
|
|
private String member(MembershipEvent e)
|
|
{
|
|
return e.getMember().getInetSocketAddress().toString();
|
|
}
|
|
|
|
private String[] cluster(MembershipEvent e)
|
|
{
|
|
Set<Member> members = e.getCluster().getMembers();
|
|
String[] cluster = new String[members.size()];
|
|
int i = 0;
|
|
for (Member m : members)
|
|
{
|
|
cluster[i++] = m.getInetSocketAddress().toString();
|
|
}
|
|
return cluster;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|