mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
规范部分代码
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
* 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.
|
||||
@@ -23,9 +23,6 @@ package me.chanjar.weixin.common.session;
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final String Package = "me.chanjar.weixin.common.session";
|
||||
|
||||
public static final String PACKAGE = "me.chanjar.weixin.common.session";
|
||||
}
|
||||
|
||||
@@ -11,13 +11,12 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
/**
|
||||
* The string manager for this package.
|
||||
*/
|
||||
protected static final StringManager sm = StringManager.getManager(Constants.Package);
|
||||
protected static final StringManager SM = StringManager.getManager(Constants.PACKAGE);
|
||||
/**
|
||||
* Type array.
|
||||
*/
|
||||
private static final String[] EMPTY_ARRAY = new String[0];
|
||||
|
||||
// ------------------------------ WxSession
|
||||
protected Map<String, Object> attributes = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The session identifier of this Session.
|
||||
@@ -73,7 +72,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionImpl.getAttribute.ise"));
|
||||
(SM.getString("sessionImpl.getAttribute.ise"));
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
@@ -86,7 +85,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
@Override
|
||||
public Enumeration<String> getAttributeNames() {
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise"));
|
||||
throw new IllegalStateException(SM.getString("sessionImpl.getAttributeNames.ise"));
|
||||
}
|
||||
|
||||
Set<String> names = new HashSet<>();
|
||||
@@ -98,7 +97,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
public void setAttribute(String name, Object value) {
|
||||
// Name cannot be null
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull"));
|
||||
throw new IllegalArgumentException(SM.getString("sessionImpl.setAttribute.namenull"));
|
||||
}
|
||||
|
||||
// Null value is the same as removeAttribute()
|
||||
@@ -109,7 +108,7 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
// Validate our current state
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
throw new IllegalStateException(SM.getString("sessionImpl.setAttribute.ise", getIdInternal()));
|
||||
}
|
||||
|
||||
this.attributes.put(name, value);
|
||||
@@ -123,8 +122,9 @@ public class StandardSession implements WxSession, InternalSession {
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (!isValidInternal())
|
||||
throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise"));
|
||||
if (!isValidInternal()) {
|
||||
throw new IllegalStateException(SM.getString("sessionImpl.invalidate.ise"));
|
||||
}
|
||||
|
||||
// Cause this session to expire
|
||||
expire();
|
||||
|
||||
@@ -13,8 +13,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
*/
|
||||
public class StandardSessionManager implements WxSessionManager, InternalSessionManager {
|
||||
|
||||
protected static final StringManager sm =
|
||||
StringManager.getManager(Constants.Package);
|
||||
protected static final StringManager SM = StringManager.getManager(Constants.PACKAGE);
|
||||
/**
|
||||
* The descriptive name of this Manager implementation (for logging).
|
||||
*/
|
||||
@@ -82,7 +81,7 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
public WxSession getSession(String sessionId, boolean create) {
|
||||
if (sessionId == null) {
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionManagerImpl.getSession.ise"));
|
||||
(SM.getString("sessionManagerImpl.getSession.ise"));
|
||||
}
|
||||
|
||||
InternalSession session = findSession(sessionId);
|
||||
@@ -124,25 +123,24 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
|
||||
@Override
|
||||
public InternalSession findSession(String id) {
|
||||
|
||||
if (id == null)
|
||||
if (id == null) {
|
||||
return (null);
|
||||
}
|
||||
return this.sessions.get(id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternalSession createSession(String sessionId) {
|
||||
if (sessionId == null) {
|
||||
throw new IllegalStateException
|
||||
(sm.getString("sessionManagerImpl.createSession.ise"));
|
||||
(SM.getString("sessionManagerImpl.createSession.ise"));
|
||||
}
|
||||
|
||||
if ((this.maxActiveSessions >= 0) &&
|
||||
(getActiveSessions() >= this.maxActiveSessions)) {
|
||||
this.rejectedSessions++;
|
||||
throw new TooManyActiveSessionsException(
|
||||
sm.getString("sessionManagerImpl.createSession.tmase"),
|
||||
SM.getString("sessionManagerImpl.createSession.tmase"),
|
||||
this.maxActiveSessions);
|
||||
}
|
||||
|
||||
@@ -230,8 +228,9 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
@Override
|
||||
public void backgroundProcess() {
|
||||
this.count = (this.count + 1) % this.processExpiresFrequency;
|
||||
if (this.count == 0)
|
||||
if (this.count == 0) {
|
||||
processExpires();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,16 +242,18 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
|
||||
InternalSession sessions[] = findSessions();
|
||||
int expireHere = 0;
|
||||
|
||||
if (this.log.isDebugEnabled())
|
||||
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()) {
|
||||
}
|
||||
for (InternalSession session : sessions) {
|
||||
if (session != null && !session.isValid()) {
|
||||
expireHere++;
|
||||
}
|
||||
}
|
||||
long timeEnd = System.currentTimeMillis();
|
||||
if (this.log.isDebugEnabled())
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere);
|
||||
}
|
||||
this.processingTime += (timeEnd - timeNow);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user