forked from ltsopensource/light-task-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化 HttpCmdServer , 保证一个JVM 一个 HttpCmdServer,节约资源
- Loading branch information
1 parent
e0193d3
commit f00db84
Showing
39 changed files
with
193 additions
and
98 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
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
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
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
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
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
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
36 changes: 28 additions & 8 deletions
36
lts-core/src/main/java/com/lts/core/cmd/HttpCmdContext.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 |
---|---|---|
@@ -1,32 +1,52 @@ | ||
package com.lts.core.cmd; | ||
|
||
import com.lts.core.commons.utils.StringUtils; | ||
import com.lts.core.commons.utils.Assert; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
/** | ||
* @author Robert HG ([email protected]) on 2/17/16. | ||
*/ | ||
public class HttpCmdContext { | ||
|
||
private final Map<String, HttpCmdProcessor> processorMap = new HashMap<String, HttpCmdProcessor>(); | ||
private ReentrantLock lock = new ReentrantLock(); | ||
private final Map<String/*节点标识*/, Map<String/*cmd*/, HttpCmdProcessor>> | ||
NODE_PROCESSOR_MAP = new HashMap<String, Map<String, HttpCmdProcessor>>(); | ||
|
||
public void addCmdProcessor(HttpCmdProcessor processor) { | ||
if (processor == null) { | ||
throw new IllegalArgumentException("processor can not be null"); | ||
} | ||
|
||
String command = processor.getCommand(); | ||
String identity = processor.nodeIdentity(); | ||
Assert.hasText(identity, "nodeIdentity can't be empty"); | ||
|
||
if (StringUtils.isEmpty(command)) { | ||
throw new IllegalArgumentException("processor.command can not be null"); | ||
String command = processor.getCommand(); | ||
Assert.hasText(command, "command can't be empty"); | ||
|
||
Map<String, HttpCmdProcessor> cmdProcessorMap = NODE_PROCESSOR_MAP.get(identity); | ||
if (cmdProcessorMap == null) { | ||
lock.lock(); | ||
if (cmdProcessorMap == null) { | ||
cmdProcessorMap = new ConcurrentHashMap<String, HttpCmdProcessor>(); | ||
NODE_PROCESSOR_MAP.put(identity, cmdProcessorMap); | ||
} | ||
lock.unlock(); | ||
} | ||
processorMap.put(command, processor); | ||
cmdProcessorMap.put(command, processor); | ||
} | ||
|
||
public HttpCmdProcessor getCmdProcessor(String command) { | ||
return processorMap.get(command); | ||
public HttpCmdProcessor getCmdProcessor(String nodeIdentity, String command) { | ||
Assert.hasText(nodeIdentity, "nodeIdentity can't be empty"); | ||
|
||
Map<String, HttpCmdProcessor> cmdProcessorMap = NODE_PROCESSOR_MAP.get(nodeIdentity); | ||
if (cmdProcessorMap == null) { | ||
return null; | ||
} | ||
return cmdProcessorMap.get(command); | ||
} | ||
|
||
} |
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
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
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
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
2 changes: 1 addition & 1 deletion
2
lts-core/src/main/java/com/lts/core/exception/LtsRuntimeException.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.lts.core.exception; | ||
|
||
/** | ||
* Created by hugui.hg on 3/2/16. | ||
* @author Robert HG ([email protected]) on 3/2/16. | ||
*/ | ||
public class LtsRuntimeException extends RuntimeException { | ||
|
||
|
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 |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
|
||
import com.lts.core.cluster.Config; | ||
import com.lts.core.spi.SPI; | ||
import com.lts.core.spi.SpiKey; | ||
import com.lts.core.spi.SpiExtensionKey; | ||
|
||
/** | ||
* Robert HG ([email protected]) on 5/21/15. | ||
*/ | ||
@SPI(key = SpiKey.FAIL_STORE, dftValue = "leveldb") | ||
@SPI(key = SpiExtensionKey.FAIL_STORE, dftValue = "leveldb") | ||
public interface FailStoreFactory { | ||
|
||
public FailStore getFailStore(Config config, String storePath); | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.lts.core.json; | ||
|
||
import com.lts.core.spi.SpiKey; | ||
import com.lts.core.spi.SpiExtensionKey; | ||
import com.lts.core.spi.SPI; | ||
|
||
import java.lang.reflect.Type; | ||
|
@@ -10,7 +10,7 @@ | |
/** | ||
* @author Robert HG ([email protected]) on 11/19/15. | ||
*/ | ||
@SPI(key = SpiKey.LTS_JSON, dftValue = "fastjson") | ||
@SPI(key = SpiExtensionKey.LTS_JSON, dftValue = "fastjson") | ||
public interface JSONAdapter { | ||
|
||
public String getName(); | ||
|
Oops, something went wrong.