14 changed files with 212 additions and 258 deletions
-
161src/main/java/a8k/service/app/appctrl/mainflowctrl/A8kPublicAreaResourceMgr.java
-
5src/main/java/a8k/service/app/appctrl/mainflowctrl/MainFlowCtrlScheduler.java
-
64src/main/java/a8k/service/app/appctrl/mainflowctrl/PublicAreaResourceMgr.java
-
16src/main/java/a8k/service/app/appctrl/mainflowctrl/action/DO_FINISH_TUBE_PROCESS.java
-
8src/main/java/a8k/service/app/appctrl/mainflowctrl/action/DO_PROCESS_ERROR_PLATE.java
-
15src/main/java/a8k/service/app/appctrl/mainflowctrl/action/PLATE_OPT_SCAN.java
-
15src/main/java/a8k/service/app/appctrl/mainflowctrl/action/PROCESS_INCUBATE_COMPLETED_PLATE.java
-
9src/main/java/a8k/service/app/appctrl/mainflowctrl/action/SEQ1_ENTER_TUBEHOLDER_AND_SCAN.java
-
21src/main/java/a8k/service/app/appctrl/mainflowctrl/action/SEQ2_SWITCH_TO_THE_NEXT_TUBE.java
-
97src/main/java/a8k/service/app/appctrl/mainflowctrl/action/SEQ5_PROCESS.java
-
9src/main/java/a8k/service/app/appctrl/mainflowctrl/action/SEQ7_EJECT_TUBEHOLDER.java
-
9src/main/java/a8k/service/app/appctrl/mainflowctrl/base/A8kPublicAreaResource.java
-
17src/main/java/a8k/service/app/appctrl/mainflowctrl/base/A8kPublicAreaResourcePacket.java
-
24src/main/java/a8k/service/app/appctrl/mainflowctrl/base/PublicAreaResource.java
@ -1,161 +0,0 @@ |
|||
package a8k.service.app.appctrl.mainflowctrl; |
|||
|
|||
|
|||
import a8k.OS; |
|||
import a8k.service.app.appctrl.mainflowctrl.base.A8kPublicAreaResource; |
|||
import jakarta.annotation.PostConstruct; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.util.Assert; |
|||
|
|||
import java.util.List; |
|||
import java.util.Vector; |
|||
|
|||
@Component |
|||
public class A8kPublicAreaResourceMgr { |
|||
static Logger logger = LoggerFactory.getLogger(A8kPublicAreaResourceMgr.class); |
|||
|
|||
static public class Resource { |
|||
public A8kPublicAreaResource type; |
|||
public Boolean rented = false;//是否被租用 |
|||
public Object ownerNow = null; |
|||
public String subOwnerName = ""; |
|||
|
|||
public Resource(A8kPublicAreaResource type) { |
|||
this.type = type; |
|||
} |
|||
} |
|||
|
|||
List<Resource> resources = new Vector<>(); |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
for (A8kPublicAreaResource type : A8kPublicAreaResource.values()) { |
|||
resources.add(new Resource(type)); |
|||
} |
|||
} |
|||
|
|||
|
|||
Boolean checkResourceRentable(A8kPublicAreaResource type) { |
|||
for (Resource r : resources) { |
|||
if (r.type == type) { |
|||
return !r.rented; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 申请资源 |
|||
* @param applyer 申请者 |
|||
* @param type 资源类型 |
|||
* @return 是否申请成功 |
|||
*/ |
|||
Boolean applyForOneResourceInternal(Object applyer, String subOwnerName, A8kPublicAreaResource type) { |
|||
for (Resource r : resources) { |
|||
if (r.type == type) { |
|||
if (r.rented) { |
|||
return false; |
|||
} |
|||
r.rented = true; |
|||
r.ownerNow = applyer; |
|||
r.subOwnerName = subOwnerName; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 申请多个资源 |
|||
* @param applyer 申请者 |
|||
* @param resources 资源类型列表 |
|||
* @return 是否申请成功 |
|||
*/ |
|||
synchronized Boolean applyForResourceInternal(Object applyer, String subOwnerName, A8kPublicAreaResource... resources) { |
|||
// logger.info("{} applyForResources: {}", applyer.getClass().getSimpleName(), types); |
|||
|
|||
if (resources == null || resources.length == 0) { |
|||
return false; |
|||
} |
|||
|
|||
//检查是否所有资源都可租用 |
|||
for (A8kPublicAreaResource type : resources) { |
|||
if (!checkResourceRentable(type)) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//租用所有资源 |
|||
for (A8kPublicAreaResource type : resources) { |
|||
Boolean suc = applyForOneResourceInternal(applyer, subOwnerName, type); |
|||
Assert.isTrue(suc, "applyForResource(applyer, type) fail"); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
public void applyForResources(Object applyer, A8kPublicAreaResource... resources) { |
|||
while (true) { |
|||
Boolean suc = applyForResourceInternal(applyer, "", resources); |
|||
if (suc) |
|||
break; |
|||
|
|||
OS.forceSleep(300); |
|||
} |
|||
} |
|||
|
|||
public void applyForResources(Object applyer, String subOwnerName, A8kPublicAreaResource... resources) { |
|||
while (true) { |
|||
Boolean suc = applyForResourceInternal(applyer, subOwnerName, resources); |
|||
if (suc) |
|||
break; |
|||
|
|||
OS.forceSleep(300); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 释放资源 |
|||
* @param type 资源类型 |
|||
*/ |
|||
synchronized public void releaseResource(A8kPublicAreaResource... type) { |
|||
for (A8kPublicAreaResource t : type) { |
|||
for (Resource r : resources) { |
|||
if (r.type == t) { |
|||
r.rented = false; |
|||
r.ownerNow = null; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 释放所有资源 |
|||
* @param applyer 申请者 |
|||
*/ |
|||
synchronized public void releaseAllResource(Object applyer) { |
|||
for (Resource r : resources) { |
|||
if (r.ownerNow == applyer) { |
|||
r.rented = false; |
|||
r.ownerNow = null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
synchronized public void releaseAllResource(Object applyer, String subOwnerName) { |
|||
for (Resource r : resources) { |
|||
if (r.ownerNow == applyer) { |
|||
if (r.subOwnerName.equals(subOwnerName)) { |
|||
r.rented = false; |
|||
r.ownerNow = null; |
|||
r.subOwnerName = ""; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,64 @@ |
|||
package a8k.service.app.appctrl.mainflowctrl; |
|||
|
|||
|
|||
import a8k.OS; |
|||
import a8k.service.app.appctrl.mainflowctrl.base.PublicAreaResource; |
|||
import a8k.service.app.appctrl.mainflowctrl.base.A8kPublicAreaResourcePacket; |
|||
import jakarta.annotation.PostConstruct; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Vector; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class PublicAreaResourceMgr { |
|||
static Logger logger = LoggerFactory.getLogger(PublicAreaResourceMgr.class); |
|||
List<PublicAreaResource> resources = new Vector<>(); |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
resources.addAll(Arrays.asList(PublicAreaResource.values())); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 申请多个资源 |
|||
* @param resources 资源类型列表 |
|||
* @return 是否申请成功 |
|||
*/ |
|||
synchronized Boolean applyForResourceInternal(PublicAreaResource... resources) { |
|||
if (resources == null || resources.length == 0) { |
|||
return false; |
|||
} |
|||
|
|||
//检查是否所有资源都可租用 |
|||
for (PublicAreaResource type : resources) { |
|||
if (type.isRent()) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//租用所有资源 |
|||
for (PublicAreaResource type : resources) { |
|||
type.setRent(); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
public A8kPublicAreaResourcePacket apply(PublicAreaResource... resources) { |
|||
while (true) { |
|||
Boolean suc = applyForResourceInternal(resources); |
|||
if (suc) |
|||
break; |
|||
|
|||
OS.forceSleep(300); |
|||
} |
|||
return new A8kPublicAreaResourcePacket(Arrays.asList(resources)); |
|||
} |
|||
|
|||
} |
@ -1,9 +0,0 @@ |
|||
package a8k.service.app.appctrl.mainflowctrl.base; |
|||
|
|||
public enum A8kPublicAreaResource { |
|||
HbotArea, //HBOT |
|||
TubeSampleProcessAndTubeChannelArea, //样本取样位,试管通道 |
|||
PlateBoxArea, //板夹仓 |
|||
IncubationPlateArea, //孵育盘 |
|||
OptScanArea, //光学扫描区 |
|||
} |
@ -0,0 +1,17 @@ |
|||
package a8k.service.app.appctrl.mainflowctrl.base; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class A8kPublicAreaResourcePacket implements AutoCloseable { |
|||
List<PublicAreaResource> areas; |
|||
|
|||
public A8kPublicAreaResourcePacket(List<PublicAreaResource> areas) { |
|||
this.areas = areas; |
|||
} |
|||
|
|||
@Override public void close() { |
|||
for (PublicAreaResource area : areas) { |
|||
area.close(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package a8k.service.app.appctrl.mainflowctrl.base; |
|||
|
|||
public enum PublicAreaResource implements AutoCloseable { |
|||
HbotArea, //HBOT |
|||
TubeSampleProcessAndTubeChannelArea, //样本取样位,试管通道 |
|||
PlateBoxArea, //板夹仓 |
|||
IncubationPlateArea, //孵育盘 |
|||
OptScanArea, |
|||
; //光学扫描区 |
|||
|
|||
Boolean rent = false; |
|||
|
|||
synchronized @Override public void close() { |
|||
rent = false; |
|||
} |
|||
|
|||
synchronized public void setRent() { |
|||
rent = true; |
|||
} |
|||
|
|||
synchronized public Boolean isRent() { |
|||
return rent; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue