Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUSTCOM-146 Parametrize *Cache maps #4377

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public class HazelcastTimerStore extends NonPersistentEJBTimerService {
private static final String EJB_TIMER_CONTAINER_CACHE_NAME = "HZEjbTmerContainerCache";
private static final String EJB_TIMER_APPLICAION_CACHE_NAME = "HZEjbTmerApplicationCache";

private final IMap pkCache;
private final IMap containerCache;
private final IMap applicationCache;
private final IMap<String, HZTimer> pkCache;
private final IMap<Long, Set<TimerPrimaryKey>> containerCache;
private final IMap<Long, Set<TimerPrimaryKey>> applicationCache;
private final String serverName;

private static final Logger logger
Expand Down Expand Up @@ -111,7 +111,7 @@ public HazelcastTimerStore(HazelcastCore core) throws Exception {

private void removeTimers(Set<TimerPrimaryKey> timerIdsToRemove) {
for (TimerPrimaryKey timerPrimaryKey : timerIdsToRemove) {
removeTimer((HZTimer) pkCache.get(timerPrimaryKey.timerId));
removeTimer(pkCache.get(timerPrimaryKey.timerId));
}
}

Expand All @@ -122,15 +122,15 @@ protected void _createTimer(TimerPrimaryKey timerId, long containerId, long appl
pkCache.put(timerId.timerId, new HZTimer(timerId, containerId, applicationId, timedObjectPrimaryKey, server_name, server_name, initialExpiration, intervalDuration, schedule, timerConfig));

// add to container cache
HashSet<TimerPrimaryKey> keysForContainer = (HashSet<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> keysForContainer = containerCache.get(containerId);
if (keysForContainer == null) {
keysForContainer = new HashSet<>();
}
keysForContainer.add(timerId);
containerCache.put(containerId, keysForContainer);

// add to application cache
HashSet<TimerPrimaryKey> keysForApp = (HashSet<TimerPrimaryKey>) applicationCache.get(applicationId);
Set<TimerPrimaryKey> keysForApp = applicationCache.get(applicationId);
if (keysForApp == null) {
keysForApp = new HashSet<>();
}
Expand Down Expand Up @@ -162,7 +162,7 @@ protected void _createTimer(TimerPrimaryKey timerId, long containerId, long appl
public void destroyAllTimers(long applicationId) {

// remove all timers
Set<TimerPrimaryKey> timerIds = (Set<TimerPrimaryKey>) applicationCache.get(applicationId);
Set<TimerPrimaryKey> timerIds = applicationCache.get(applicationId);

if (timerIds == null || timerIds.isEmpty()) {
if (logger.isLoggable(Level.INFO)) {
Expand All @@ -182,7 +182,7 @@ public void destroyAllTimers(long applicationId) {

@Override
public void destroyTimers(long containerId) {
Set<TimerPrimaryKey> timerIds = (Set<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> timerIds = containerCache.get(containerId);

if (timerIds == null || timerIds.isEmpty()) {
if (logger.isLoggable(Level.INFO)) {
Expand All @@ -201,7 +201,7 @@ protected void cancelTimer(TimerPrimaryKey timerId) throws FinderException, Exce
// Check non-persistent timers first
if (!cancelNonPersistentTimer(timerId)) {

HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (timer != null) {

TransactionManager tm = ejbContainerUtil.getTransactionManager();
Expand All @@ -226,7 +226,7 @@ protected Serializable getInfo(TimerPrimaryKey timerId) throws FinderException {
return super.getInfo(timerId);
}

HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);

if (timer == null) {
throw new FinderException("Unable to find timer " + timerId);
Expand Down Expand Up @@ -270,12 +270,12 @@ protected void cancelTimersByKey(long containerId, Object primaryKey) {
// Get *all* timers for this entity bean identity. This includes
// even timers *not* owned by this server instance, but that
// are associated with the same entity bean and primary key.
Collection<TimerPrimaryKey> timers = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> timers = containerCache.get(containerId);

if (timers != null) {
HashSet<HZTimer> timersToCancel = new HashSet<>();
for (TimerPrimaryKey timer : timers) {
HZTimer hzTimer = (HZTimer) pkCache.get(((TimerPrimaryKey)primaryKey).timerId);
HZTimer hzTimer = pkCache.get(((TimerPrimaryKey)primaryKey).timerId);
if (hzTimer != null && hzTimer.getTimedObjectPk().equals(primaryKey)) {
timersToCancel.add(hzTimer);
}
Expand All @@ -292,7 +292,7 @@ public void createSchedules(long containerId, long applicationId, Map<MethodDesc
TransactionManager tm = ejbContainerUtil.getTransactionManager();
try {
tm.begin();
Collection<TimerPrimaryKey> keys = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> keys = containerCache.get(containerId);

if (keys == null || keys.isEmpty()) {
// No timers owned by this EJB
Expand Down Expand Up @@ -339,7 +339,7 @@ public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_n
@Override
protected void expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean) {

HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (timer != null) {
removeTimer(timer);
}
Expand All @@ -352,7 +352,7 @@ protected void expungeTimer(TimerPrimaryKey timerId, boolean removeTimerBean) {
protected Collection<TimerPrimaryKey> getTimerIds(Collection<Long> containerIds) {
Collection<TimerPrimaryKey> result = super.getTimerIds(containerIds);
for (Long containerId : containerIds) {
Collection<TimerPrimaryKey> colKeys = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> colKeys = containerCache.get(containerId);
if (colKeys != null) {
result.addAll(colKeys);
}
Expand All @@ -372,16 +372,16 @@ protected Collection<TimerPrimaryKey> getTimerIds(long containerId, Object timed
= new HashSet<TimerPrimaryKey>();

if (timedObjectPrimaryKey == null) {
Collection<TimerPrimaryKey> contKeys = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Set<TimerPrimaryKey> contKeys = containerCache.get(containerId);
if (contKeys != null) {
timerIdsForTimedObject.addAll(contKeys);
}
} else {

Collection<TimerPrimaryKey> timersForTimedObject = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Collection<TimerPrimaryKey> timersForTimedObject = containerCache.get(containerId);
if (timersForTimedObject != null) {
for (TimerPrimaryKey timer : timersForTimedObject) {
HZTimer hzTimer = (HZTimer) pkCache.get(timer.timerId);
HZTimer hzTimer = pkCache.get(timer.timerId);
if (hzTimer != null && hzTimer.getTimedObjectPk().equals(timedObjectPrimaryKey)) {
timerIdsForTimedObject.add(timer);
}
Expand Down Expand Up @@ -463,7 +463,7 @@ protected boolean isPersistent(TimerPrimaryKey timerId) throws FinderException {
protected boolean isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTimerState timerState) {
boolean result = true;
if (timerState.isPersistent()) {
HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (timer == null || !timer.getMemberName().equals(serverName)) {
result = false;
}
Expand Down Expand Up @@ -499,7 +499,7 @@ protected boolean isValidTimerForThisServer(TimerPrimaryKey timerId, RuntimeTime

@Override
public String[] listTimers(String[] serverIds) {
return listTimers((Collection<HZTimer>)pkCache.values(), serverIds);
return listTimers(pkCache.values(), serverIds);
}

@Override
Expand All @@ -525,8 +525,8 @@ public int migrateTimers(String fromOwnerId) {
HashMap<String, HZTimer> toRestore = new HashMap<>();
int totalTimersMigrated = 0;

for (String pk : (Collection<String>) pkCache.keySet()) {
HZTimer hZTimer = (HZTimer) pkCache.get(pk);
for (String pk : pkCache.keySet()) {
HZTimer hZTimer = pkCache.get(pk);
if (hZTimer.getOwnerId().equals(fromOwnerId)) {
toRestore.put(pk, hZTimer);
hZTimer.setOwnerId(ownerIdOfThisServer);
Expand Down Expand Up @@ -594,11 +594,11 @@ protected Map<TimerPrimaryKey, Method> recoverAndCreateSchedules(long containerI
Set<HZTimer> activeTimers = new HashSet<>();

// get all timers for this container
Collection<TimerPrimaryKey> containerKeys = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
Collection<TimerPrimaryKey> deadKeys = new HashSet<>();
Set<TimerPrimaryKey> containerKeys = containerCache.get(containerId);
Set<TimerPrimaryKey> deadKeys = new HashSet<>();
if (containerKeys != null) {
for (TimerPrimaryKey containerKey : containerKeys) {
HZTimer timer = (HZTimer) pkCache.get(containerKey.timerId);
HZTimer timer = pkCache.get(containerKey.timerId);
if (timer != null && timer.getMemberName().equals(this.serverName)) {
activeTimers.add(timer);
} else if (timer == null) {
Expand Down Expand Up @@ -673,7 +673,7 @@ protected boolean redeliverTimeout(RuntimeTimerState timerState) {
protected void resetLastExpiration(TimerPrimaryKey timerId, RuntimeTimerState timerState
) {
if (timerState.isPersistent()) {
HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (null == timer) {
return;
}
Expand Down Expand Up @@ -721,7 +721,7 @@ protected boolean timerExists(TimerPrimaryKey timerId) {
// @@@ We can't assume this server instance owns the persistent timer
// so always ask the database. Investigate possible use of
// timer cache for optimization.
HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (timer != null) {
// Make sure timer hasn't been cancelled within the current tx.
exists = true;
Expand All @@ -735,11 +735,11 @@ protected boolean timerExists(TimerPrimaryKey timerId) {
protected void stopTimers(long containerId
) {
super.stopTimers(containerId);
stopTimers((Set<TimerPrimaryKey>) containerCache.get(containerId));
stopTimers(containerCache.get(containerId));
}

private HZTimer getPersistentTimer(TimerPrimaryKey timerId) throws FinderException {
HZTimer result = (HZTimer) pkCache.get(timerId.timerId);
HZTimer result = pkCache.get(timerId.timerId);
if (result == null) {
throw new FinderException("Unable to find timer " + timerId);
}
Expand All @@ -749,13 +749,13 @@ private HZTimer getPersistentTimer(TimerPrimaryKey timerId) throws FinderExcepti
private void removeTimer(HZTimer timer) {
pkCache.remove(timer.getKey().timerId);

Collection<TimerPrimaryKey> keys = (Collection<TimerPrimaryKey>) applicationCache.get(timer.getApplicationId());
Set<TimerPrimaryKey> keys = applicationCache.get(timer.getApplicationId());
if (keys != null) {
keys.remove(timer.getKey());
applicationCache.put(timer.getApplicationId(), keys);
}

keys = (Collection<TimerPrimaryKey>) containerCache.get(timer.getContainerId());
keys = containerCache.get(timer.getContainerId());
if (keys != null) {
keys.remove(timer.getKey());
containerCache.put(timer.getContainerId(), keys);
Expand Down Expand Up @@ -786,7 +786,7 @@ private boolean checkForTimerValidity(TimerPrimaryKey timerId) {

ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(HazelcastTimerStore.class.getClassLoader());
HZTimer timer = (HZTimer) pkCache.get(timerId.timerId);
HZTimer timer = pkCache.get(timerId.timerId);
if (timer != null && timer.getMemberName().equals(this.serverName)) {
result = true;
}
Expand Down Expand Up @@ -829,7 +829,7 @@ private Collection<HZTimer> _restoreTimers(Collection<HZTimer> timersEligibleFor
// Do timer restoration in two passes. The first pass updates
// the timer cache with each timer. The second pass schedules
// the JDK timer tasks.
Map timersToRestore = new HashMap();
Map<RuntimeTimerState, Date> timersToRestore = new HashMap<>();
Set<TimerPrimaryKey> timerIdsToRemove = new HashSet<>();
Set<HZTimer> result = new HashSet<HZTimer>();

Expand Down Expand Up @@ -1004,7 +1004,7 @@ private Set<HZTimer> _restoreTimers(Set<HZTimer> timersEligibleForRestoration) {
// Do timer restoration in two passes. The first pass updates
// the timer cache with each timer. The second pass schedules
// the JDK timer tasks.
Map timersToRestore = new HashMap();
Map<RuntimeTimerState, Date> timersToRestore = new HashMap<>();
Set<TimerPrimaryKey> timerIdsToRemove = new HashSet<>();
Set<HZTimer> result = new HashSet<HZTimer>();

Expand Down Expand Up @@ -1167,7 +1167,7 @@ private Set<HZTimer> _restoreTimers(Set<HZTimer> timersEligibleForRestoration) {

private Collection<HZTimer> findActiveTimersOwnedByThisServer() {
HashSet<HZTimer> result = new HashSet<>();
for (HZTimer timer : (Collection<HZTimer>) pkCache.values()) {
for (HZTimer timer : pkCache.values()) {
if (timer.getMemberName().equals(this.serverName)) {
result.add(timer);
}
Expand Down