simter-context

System Context Interface and holder

License

License

MIT
GroupId

GroupId

tech.simter
ArtifactId

ArtifactId

simter-context
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

simter-context
System Context Interface and holder
Project URL

Project URL

https://github.com/simter/simter-context
Project Organization

Project Organization

simter
Source Code Management

Source Code Management

https://github.com/simter/simter-context.git

Download simter-context

How to add to project

<!-- https://jarcasting.com/artifacts/tech.simter/simter-context/ -->
<dependency>
    <groupId>tech.simter</groupId>
    <artifactId>simter-context</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/tech.simter/simter-context/
implementation 'tech.simter:simter-context:1.1.0'
// https://jarcasting.com/artifacts/tech.simter/simter-context/
implementation ("tech.simter:simter-context:1.1.0")
'tech.simter:simter-context:jar:1.1.0'
<dependency org="tech.simter" name="simter-context" rev="1.1.0">
  <artifact name="simter-context" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.simter', module='simter-context', version='1.1.0')
)
libraryDependencies += "tech.simter" % "simter-context" % "1.1.0"
[tech.simter/simter-context "1.1.0"]

Dependencies

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.5.0

Project Modules

There are no modules declared in this project.

simter-context [中文]

A simple and powerful utils class tech.simter.Context for share data during the same thread lifecycle.

This tools use thread-local variables to make each thread has its own initialized share data. You don't need to transfer context data through method arguments, just use Context.get(key) to get its value inside the method.

Installation

<dependency>
  <groupId>tech.simter</groupId>
  <artifactId>simter-context</artifactId>
  <version>1.0.0</version>
</dependency>

Requirement

  • Java 8+

Usage

// set share data anywhere
Context.set("userId", new Long(0));
Context.set("userName", "RJ");
...

void someMethodInOtherClass(){
  // get shared data by key anywhere
  Long userId = Context.get("userId");
  String userName = Context.get("userName");
  
  // or get all shared data
  Map<String, Object> all = Context.get();
  ...
}
...

// delete shared data anywhere
Context.remove("userId");
...

You can see that it just like to get a static constant value. But you need to know the difference: A static constant always has the same value even in different thread. But the context data is isolated between each thread.

Build

mvn clean package

Deploy

First take a look at simter-parent deploy config.

Deploy to LAN Nexus Repository

mvn clean deploy -P lan

Deploy to Sonatype Repository

mvn clean deploy -P sonatype

After deployed, login into https://oss.sonatype.org. Through Staging Repositories, search this package, then close and release it. After couple hours, it will be synced to Maven Central Repository.

Deploy to Bintray Repository

mvn clean deploy -P bintray

Will deploy to https://api.bintray.com/maven/simter/maven/tech.simter:simter-context/;publish=1. So first create a package https://bintray.com/simter/maven/tech.simter:simter-context on Bintray. After deployed, check it from https://jcenter.bintray.com/tech/simter/simter-context.

tech.simter

Versions

Version
1.1.0
1.0.0
0.4.0
0.3.0
0.1.0