mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
fix some warnings in common modules
This commit is contained in:
@@ -18,7 +18,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
*/
|
||||
protected static final String EMPTY_ARRAY[] = new String[0];
|
||||
// ------------------------------ WxSession
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The session identifier of this Session.
|
||||
*/
|
||||
@@ -47,7 +47,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
/**
|
||||
* The current accessed time for this session.
|
||||
*/
|
||||
protected volatile long thisAccessedTime = creationTime;
|
||||
protected volatile long thisAccessedTime = this.creationTime;
|
||||
/**
|
||||
* The default maximum inactive interval for Sessions created by
|
||||
* this Manager.
|
||||
@@ -77,7 +77,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
if (name == null) return null;
|
||||
|
||||
return (attributes.get(name));
|
||||
return (this.attributes.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,8 +86,8 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionImpl.getAttributeNames.ise"));
|
||||
|
||||
Set<String> names = new HashSet<String>();
|
||||
names.addAll(attributes.keySet());
|
||||
Set<String> names = new HashSet<>();
|
||||
names.addAll(this.attributes.keySet());
|
||||
return Collections.enumeration(names);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
throw new IllegalStateException(sm.getString(
|
||||
"sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
|
||||
attributes.put(name, value);
|
||||
this.attributes.put(name, value);
|
||||
|
||||
}
|
||||
|
||||
@@ -132,10 +132,10 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
public WxSession getSession() {
|
||||
|
||||
if (facade == null) {
|
||||
facade = new StandardSessionFacade(this);
|
||||
if (this.facade == null) {
|
||||
this.facade = new StandardSessionFacade(this);
|
||||
}
|
||||
return (facade);
|
||||
return (this.facade);
|
||||
|
||||
}
|
||||
|
||||
@@ -157,15 +157,15 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (accessCount.get() > 0) {
|
||||
if (this.accessCount.get() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (maxInactiveInterval > 0) {
|
||||
if (this.maxInactiveInterval > 0) {
|
||||
long timeNow = System.currentTimeMillis();
|
||||
int timeIdle;
|
||||
timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
|
||||
if (timeIdle >= maxInactiveInterval) {
|
||||
timeIdle = (int) ((timeNow - this.thisAccessedTime) / 1000L);
|
||||
if (timeIdle >= this.maxInactiveInterval) {
|
||||
expire();
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
if (name == null) return;
|
||||
|
||||
// Remove this attribute from our collection
|
||||
attributes.remove(name);
|
||||
this.attributes.remove(name);
|
||||
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
// Check to see if session has already been invalidated.
|
||||
// Do not check expiring at this point as expire should not return until
|
||||
// isValid is false
|
||||
if (!isValid)
|
||||
if (!this.isValid)
|
||||
return;
|
||||
|
||||
synchronized (this) {
|
||||
@@ -210,24 +210,24 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
// Double check locking - isValid needs to be volatile
|
||||
// The check of expiring is to ensure that an infinite loop is not
|
||||
// entered as per bug 56339
|
||||
if (expiring || !isValid)
|
||||
if (this.expiring || !this.isValid)
|
||||
return;
|
||||
|
||||
if (manager == null)
|
||||
if (this.manager == null)
|
||||
return;
|
||||
|
||||
// Mark this session as "being expired"
|
||||
expiring = true;
|
||||
this.expiring = true;
|
||||
|
||||
accessCount.set(0);
|
||||
this.accessCount.set(0);
|
||||
|
||||
// Remove this session from our manager's active sessions
|
||||
manager.remove(this, true);
|
||||
this.manager.remove(this, true);
|
||||
|
||||
|
||||
// We have completed expire of this session
|
||||
setValid(false);
|
||||
expiring = false;
|
||||
this.expiring = false;
|
||||
|
||||
// Unbind any objects associated with this session
|
||||
String keys[] = keys();
|
||||
@@ -244,7 +244,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
public void access() {
|
||||
|
||||
this.thisAccessedTime = System.currentTimeMillis();
|
||||
accessCount.incrementAndGet();
|
||||
this.accessCount.incrementAndGet();
|
||||
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
public void endAccess() {
|
||||
|
||||
this.thisAccessedTime = System.currentTimeMillis();
|
||||
accessCount.decrementAndGet();
|
||||
this.accessCount.decrementAndGet();
|
||||
|
||||
}
|
||||
|
||||
@@ -273,13 +273,13 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
if ((this.id != null) && (manager != null))
|
||||
manager.remove(this);
|
||||
if ((this.id != null) && (this.manager != null))
|
||||
this.manager.remove(this);
|
||||
|
||||
this.id = id;
|
||||
|
||||
if (manager != null)
|
||||
manager.add(this);
|
||||
if (this.manager != null)
|
||||
this.manager.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +289,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
*/
|
||||
protected String[] keys() {
|
||||
|
||||
return attributes.keySet().toArray(EMPTY_ARRAY);
|
||||
return this.attributes.keySet().toArray(EMPTY_ARRAY);
|
||||
|
||||
}
|
||||
|
||||
@@ -300,31 +300,31 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
StandardSession session = (StandardSession) o;
|
||||
|
||||
if (creationTime != session.creationTime) return false;
|
||||
if (expiring != session.expiring) return false;
|
||||
if (isValid != session.isValid) return false;
|
||||
if (maxInactiveInterval != session.maxInactiveInterval) return false;
|
||||
if (thisAccessedTime != session.thisAccessedTime) return false;
|
||||
if (!accessCount.equals(session.accessCount)) return false;
|
||||
if (!attributes.equals(session.attributes)) return false;
|
||||
if (!facade.equals(session.facade)) return false;
|
||||
if (!id.equals(session.id)) return false;
|
||||
return manager.equals(session.manager);
|
||||
if (this.creationTime != session.creationTime) return false;
|
||||
if (this.expiring != session.expiring) return false;
|
||||
if (this.isValid != session.isValid) return false;
|
||||
if (this.maxInactiveInterval != session.maxInactiveInterval) return false;
|
||||
if (this.thisAccessedTime != session.thisAccessedTime) return false;
|
||||
if (!this.accessCount.equals(session.accessCount)) return false;
|
||||
if (!this.attributes.equals(session.attributes)) return false;
|
||||
if (!this.facade.equals(session.facade)) return false;
|
||||
if (!this.id.equals(session.id)) return false;
|
||||
return this.manager.equals(session.manager);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = attributes.hashCode();
|
||||
result = 31 * result + id.hashCode();
|
||||
result = 31 * result + (isValid ? 1 : 0);
|
||||
result = 31 * result + (expiring ? 1 : 0);
|
||||
result = 31 * result + manager.hashCode();
|
||||
result = 31 * result + (int) (creationTime ^ (creationTime >>> 32));
|
||||
result = 31 * result + (int) (thisAccessedTime ^ (thisAccessedTime >>> 32));
|
||||
result = 31 * result + maxInactiveInterval;
|
||||
result = 31 * result + facade.hashCode();
|
||||
result = 31 * result + accessCount.hashCode();
|
||||
int result = this.attributes.hashCode();
|
||||
result = 31 * result + this.id.hashCode();
|
||||
result = 31 * result + (this.isValid ? 1 : 0);
|
||||
result = 31 * result + (this.expiring ? 1 : 0);
|
||||
result = 31 * result + this.manager.hashCode();
|
||||
result = 31 * result + (int) (this.creationTime ^ (this.creationTime >>> 32));
|
||||
result = 31 * result + (int) (this.thisAccessedTime ^ (this.thisAccessedTime >>> 32));
|
||||
result = 31 * result + this.maxInactiveInterval;
|
||||
result = 31 * result + this.facade.hashCode();
|
||||
result = 31 * result + this.accessCount.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,32 +14,32 @@ public class StandardSessionFacade implements WxSession {
|
||||
}
|
||||
|
||||
public InternalSession getInternalSession() {
|
||||
return (InternalSession) session;
|
||||
return (InternalSession) this.session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(String name) {
|
||||
return session.getAttribute(name);
|
||||
return this.session.getAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
return session.getAttributeNames();
|
||||
return this.session.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
session.setAttribute(name, value);
|
||||
this.session.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttribute(String name) {
|
||||
session.removeAttribute(name);
|
||||
this.session.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
session.invalidate();
|
||||
this.session.invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
* The set of currently active Sessions for this Manager, keyed by
|
||||
* session identifier.
|
||||
*/
|
||||
protected Map<String, InternalSession> sessions = new ConcurrentHashMap<String, InternalSession>();
|
||||
protected Map<String, InternalSession> sessions = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The maximum number of active Sessions allowed, or -1 for no limit.
|
||||
*/
|
||||
@@ -117,7 +117,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
@Override
|
||||
public void remove(InternalSession session, boolean update) {
|
||||
if (session.getIdInternal() != null) {
|
||||
sessions.remove(session.getIdInternal());
|
||||
this.sessions.remove(session.getIdInternal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
|
||||
if (id == null)
|
||||
return (null);
|
||||
return sessions.get(id);
|
||||
return this.sessions.get(id);
|
||||
|
||||
}
|
||||
|
||||
@@ -138,12 +138,12 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
(sm.getString("sessionManagerImpl.createSession.ise"));
|
||||
}
|
||||
|
||||
if ((maxActiveSessions >= 0) &&
|
||||
(getActiveSessions() >= maxActiveSessions)) {
|
||||
rejectedSessions++;
|
||||
if ((this.maxActiveSessions >= 0) &&
|
||||
(getActiveSessions() >= this.maxActiveSessions)) {
|
||||
this.rejectedSessions++;
|
||||
throw new TooManyActiveSessionsException(
|
||||
sm.getString("sessionManagerImpl.createSession.tmase"),
|
||||
maxActiveSessions);
|
||||
this.maxActiveSessions);
|
||||
}
|
||||
|
||||
// Recycle or create a Session instance
|
||||
@@ -155,7 +155,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
session.setMaxInactiveInterval(this.maxInactiveInterval);
|
||||
String id = sessionId;
|
||||
session.setId(id);
|
||||
sessionCounter++;
|
||||
this.sessionCounter++;
|
||||
|
||||
return (session);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
|
||||
@Override
|
||||
public int getActiveSessions() {
|
||||
return sessions.size();
|
||||
return this.sessions.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -185,17 +185,17 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
public void add(InternalSession session) {
|
||||
|
||||
// 当第一次有session创建的时候,开启session清理线程
|
||||
if (!backgroundProcessStarted.getAndSet(true)) {
|
||||
if (!this.backgroundProcessStarted.getAndSet(true)) {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
// 每秒清理一次
|
||||
Thread.sleep(backgroundProcessorDelay * 1000l);
|
||||
Thread.sleep(StandardSessionManager.this.backgroundProcessorDelay * 1000l);
|
||||
backgroundProcess();
|
||||
} catch (InterruptedException e) {
|
||||
log.error("SessionManagerImpl.backgroundProcess error", e);
|
||||
StandardSessionManager.this.log.error("SessionManagerImpl.backgroundProcess error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,12 +204,12 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
t.start();
|
||||
}
|
||||
|
||||
sessions.put(session.getIdInternal(), session);
|
||||
this.sessions.put(session.getIdInternal(), session);
|
||||
int size = getActiveSessions();
|
||||
if (size > maxActive) {
|
||||
synchronized (maxActiveUpdateLock) {
|
||||
if (size > maxActive) {
|
||||
maxActive = size;
|
||||
if (size > this.maxActive) {
|
||||
synchronized (this.maxActiveUpdateLock) {
|
||||
if (size > this.maxActive) {
|
||||
this.maxActive = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,14 +223,14 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
@Override
|
||||
public InternalSession[] findSessions() {
|
||||
|
||||
return sessions.values().toArray(new InternalSession[0]);
|
||||
return this.sessions.values().toArray(new InternalSession[0]);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backgroundProcess() {
|
||||
count = (count + 1) % processExpiresFrequency;
|
||||
if (count == 0)
|
||||
this.count = (this.count + 1) % this.processExpiresFrequency;
|
||||
if (this.count == 0)
|
||||
processExpires();
|
||||
}
|
||||
|
||||
@@ -243,17 +243,17 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
InternalSession sessions[] = findSessions();
|
||||
int expireHere = 0;
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length);
|
||||
if (this.log.isDebugEnabled())
|
||||
this.log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length);
|
||||
for (int i = 0; i < sessions.length; i++) {
|
||||
if (sessions[i] != null && !sessions[i].isValid()) {
|
||||
expireHere++;
|
||||
}
|
||||
}
|
||||
long timeEnd = System.currentTimeMillis();
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere);
|
||||
processingTime += (timeEnd - timeNow);
|
||||
if (this.log.isDebugEnabled())
|
||||
this.log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere);
|
||||
this.processingTime += (timeEnd - timeNow);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class TooManyActiveSessionsException
|
||||
int maxActive) {
|
||||
super(message);
|
||||
|
||||
maxActiveSessions = maxActive;
|
||||
this.maxActiveSessions = maxActive;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +49,6 @@ public class TooManyActiveSessionsException
|
||||
* @return The maximum number of sessions allowed by the session manager.
|
||||
*/
|
||||
public int getMaxActiveSessions() {
|
||||
return maxActiveSessions;
|
||||
return this.maxActiveSessions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user