Class TerminalContext
-
- All Implemented Interfaces:
public class TerminalContextUsed at the service level, TransmittableThreadLocal has automatic thread inheritance. Set by TerminalInterceptor.preHandle, cleaned up by afterCompletion. Note: No WeakReference Leak due to static and Interceptor cleanup.
- Since:
2019-11-25
trydofor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceTerminalContext.Listenerpublic classTerminalContext.Contextpublic classTerminalContext.Builder
-
Field Summary
Fields Modifier and Type Field Description public final static TerminalContext.ContextNull
-
Constructor Summary
Constructors Constructor Description TerminalContext()
-
Method Summary
Modifier and Type Method Description static voidinitTimeZone(@NotNull() TimeZone zoneId)init default zoneId static voidinitLocale(@NotNull() Locale locale)init default locale static ZoneIddefaultZoneId()get default zoneId static TimeZonedefaultTimeZone()get default timezone static LocaledefaultLocale()get default locale static ZoneIdcurrentZoneId()get current use or system zoneId static TimeZonecurrentTimeZone()get current use or system timezone static LocalecurrentLocale()get current use or system locale static longcurrentLoginUser()only login user, throw TerminalException if not login static TerminalContext.ListenerregisterListener(String name, TerminalContext.Listener listener)set login and logout listener. static TerminalContext.ListenerremoveListener(String name)remove login and logout listener by name static TerminalContext.Contextget()only login user, throw TerminalException if not login static TerminalContext.Contextget(boolean onlyLogin)unlogined user as Guest or throw TerminalException static voidlogin(@Nullable() TerminalContext.Context ctx)login if ctx is not null/Null, else logout static TerminalContext.Contextlogout()logout the context and fireContextChange static TerminalContext.Contextlogout(boolean fire)logout the context and whether to fireContextChange -
-
Method Detail
-
initTimeZone
static void initTimeZone(@NotNull() TimeZone zoneId)
init default zoneId
-
initLocale
static void initLocale(@NotNull() Locale locale)
init default locale
-
defaultZoneId
@NotNull() static ZoneId defaultZoneId()
get default zoneId
-
defaultTimeZone
@NotNull() static TimeZone defaultTimeZone()
get default timezone
-
defaultLocale
@NotNull() static Locale defaultLocale()
get default locale
-
currentZoneId
@NotNull() static ZoneId currentZoneId()
get current use or system zoneId
- Returns:
zoneId
-
currentTimeZone
@NotNull() static TimeZone currentTimeZone()
get current use or system timezone
-
currentLocale
@NotNull() static Locale currentLocale()
get current use or system locale
- Returns:
locale
-
currentLoginUser
static long currentLoginUser()
only login user, throw TerminalException if not login
-
registerListener
static TerminalContext.Listener registerListener(String name, TerminalContext.Listener listener)
set login and logout listener. context is null for logout, else for login.
- Parameters:
name- name of listenerlistener- the listener- Returns:
null or old value
-
removeListener
static TerminalContext.Listener removeListener(String name)
remove login and logout listener by name
- Parameters:
name- name of listener- Returns:
null or old value
-
get
@NotNull() static TerminalContext.Context get()
only login user, throw TerminalException if not login
-
get
@NotNull() static TerminalContext.Context get(boolean onlyLogin)
unlogined user as Guest or throw TerminalException
- Parameters:
onlyLogin- only login user or guest
-
login
static void login(@Nullable() TerminalContext.Context ctx)
login if ctx is not null/Null, else logout
-
logout
@Nullable() static TerminalContext.Context logout()
logout the context and fireContextChange
-
logout
@Nullable() static TerminalContext.Context logout(boolean fire)
logout the context and whether to fireContextChange
- Parameters:
fire- whether to fireContextChange
-
-
-
-