-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSessionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.apache.roller.weblogger.ui.core; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.roller.weblogger.pojos.User; | ||
import org.apache.roller.weblogger.util.cache.Cache; | ||
import org.apache.roller.weblogger.util.cache.CacheHandlerAdapter; | ||
import org.apache.roller.weblogger.util.cache.CacheManager; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class RollerSessionManager { | ||
private static final Log log = LogFactory.getLog(RollerSessionManager.class); | ||
private static final String CACHE_ID = "roller.session.cache"; | ||
|
||
private final Cache sessionCache; | ||
|
||
public static RollerSessionManager getInstance() { | ||
return RollerSessionManager.SingletonHolder.INSTANCE; | ||
} | ||
|
||
private static class SingletonHolder { | ||
private static final RollerSessionManager INSTANCE = new RollerSessionManager(); | ||
} | ||
|
||
private class SessionCacheHandler extends CacheHandlerAdapter { | ||
public void invalidateUser(User user) { | ||
if (user != null && user.getUserName() != null) { | ||
sessionCache.remove(user.getUserName()); | ||
} | ||
} | ||
} | ||
|
||
private RollerSessionManager() { | ||
Map<String, String> cacheProps = new HashMap<>(); | ||
cacheProps.put("id", CACHE_ID); | ||
this.sessionCache = CacheManager.constructCache(null, cacheProps); | ||
SessionCacheHandler cacheHandler = new SessionCacheHandler(); | ||
CacheManager.registerHandler(cacheHandler); | ||
} | ||
|
||
public void register(String userName, RollerSession session) { | ||
if (userName != null && session != null) { | ||
this.sessionCache.put(userName, session); | ||
log.debug("Registered session for user: " + userName); | ||
} | ||
} | ||
|
||
public RollerSession get(String userName) { | ||
if (userName != null) { | ||
return (RollerSession) this.sessionCache.get(userName); | ||
} | ||
return null; | ||
} | ||
|
||
public void invalidate(String userName) { | ||
if (userName != null) { | ||
this.sessionCache.remove(userName); | ||
log.debug("Invalidated session for user: " + userName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/src/main/java/org/apache/roller/weblogger/util/cache/CacheHandlerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. The ASF licenses this file to You | ||
* under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. For additional information regarding | ||
* copyright in this work, please see the NOTICE file in the top level | ||
* directory of this distribution. | ||
*/ | ||
package org.apache.roller.weblogger.util.cache; | ||
|
||
import org.apache.roller.weblogger.pojos.*; | ||
|
||
public class CacheHandlerAdapter implements CacheHandler { | ||
|
||
@Override | ||
public void invalidate(WeblogEntry entry) { | ||
} | ||
|
||
@Override | ||
public void invalidate(Weblog website) { | ||
} | ||
|
||
@Override | ||
public void invalidate(WeblogBookmark bookmark) { | ||
} | ||
|
||
@Override | ||
public void invalidate(WeblogBookmarkFolder folder) { | ||
} | ||
|
||
@Override | ||
public void invalidate(WeblogEntryComment comment) { | ||
} | ||
|
||
@Override | ||
public void invalidate(User user) { | ||
} | ||
|
||
@Override | ||
public void invalidate(WeblogCategory category) { | ||
} | ||
|
||
@Override | ||
public void invalidate(WeblogTemplate template) { | ||
} | ||
} |