diff --git a/src/main/java/com/lq/code/dto/QueueDto.java b/src/main/java/com/lq/code/dto/QueueDto.java index 6bb06d6..21c63da 100644 --- a/src/main/java/com/lq/code/dto/QueueDto.java +++ b/src/main/java/com/lq/code/dto/QueueDto.java @@ -2,6 +2,7 @@ package com.lq.code.dto; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; /** * @Author: qi @@ -10,13 +11,20 @@ import java.util.List; */ public class QueueDto { + /** + * 队列内部数组 + */ private List list; - - private int index; + /** + * 队列索引  + */ + private AtomicInteger index = new AtomicInteger(0); public QueueDto() { + this.list = new ArrayList<>(); + } public QueueDto(int size) { @@ -25,14 +33,15 @@ public class QueueDto { public void add(T t){ list.add(t); - index ++; + index.getAndIncrement(); + } - public synchronized T pop(){ + public T pop(){ T t = null; if (hasNext()) { - index--; - t = list.get(index); + index.getAndAdd(-1); + t = list.get(index.get()); } return t; } @@ -41,9 +50,10 @@ public class QueueDto { * 判断是否还有元素存在 * @return */ - public synchronized boolean hasNext(){ + public boolean hasNext(){ boolean result = true; - if (index==0){ + int nowIndex = index.get(); + if (nowIndex == 0){ result = false; } return result; @@ -51,7 +61,7 @@ public class QueueDto { public int getIndex(){ - return this.index; + return this.index.get(); } } diff --git a/src/main/java/com/lq/code/util/BeanUtil.java b/src/main/java/com/lq/code/util/BeanUtil.java index c38fdeb..32879be 100755 --- a/src/main/java/com/lq/code/util/BeanUtil.java +++ b/src/main/java/com/lq/code/util/BeanUtil.java @@ -186,6 +186,11 @@ public class BeanUtil { return set; } + /** + * 扫描包路径,并返回一个队列class + * @param packagePath + * @return + */ public static QueueDto getQueueDto(String packagePath){ QueueDto classQueueDto = new QueueDto<>(); String separator = File.separator; diff --git a/src/main/java/com/lq/jms/service/ProductService.java b/src/main/java/com/lq/jms/service/ProductService.java new file mode 100644 index 0000000..816f94e --- /dev/null +++ b/src/main/java/com/lq/jms/service/ProductService.java @@ -0,0 +1,16 @@ +package com.lq.jms.service; + +/** + * @author qi + */ +public interface ProductService { + + /** + * 发送队列消息 + * @param topic 主题 + * @param msg 消息内容 + */ + void sendQueue(String topic,String msg); + + +} diff --git a/src/main/java/com/lq/jms/service/impl/ProductServiceImpl.java b/src/main/java/com/lq/jms/service/impl/ProductServiceImpl.java new file mode 100644 index 0000000..a66e1f6 --- /dev/null +++ b/src/main/java/com/lq/jms/service/impl/ProductServiceImpl.java @@ -0,0 +1,25 @@ +package com.lq.jms.service.impl; + +import com.lq.jms.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.stereotype.Service; + +/** + * @author qi + */ +@Service +public class ProductServiceImpl implements ProductService { + + @Autowired + private JmsTemplate jmsTemplate; + + + @Override + public void sendQueue(String topic, String msg) { + + jmsTemplate.convertAndSend(topic,msg); + } + + +} diff --git a/src/main/resources/spring-import.xml b/src/main/resources/spring-import.xml index b7fc4f8..01d8f73 100644 --- a/src/main/resources/spring-import.xml +++ b/src/main/resources/spring-import.xml @@ -13,7 +13,8 @@ - + + \ No newline at end of file diff --git a/src/main/resources/spring/spring-activitMq.xml b/src/main/resources/spring/spring-activitMq.xml index 8b26916..8b8fae8 100644 --- a/src/main/resources/spring/spring-activitMq.xml +++ b/src/main/resources/spring/spring-activitMq.xml @@ -1,31 +1,37 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/lq/SysPermissionServiceTest.java b/src/test/java/com/lq/SysPermissionServiceTest.java index 7b97624..c5306f4 100644 --- a/src/test/java/com/lq/SysPermissionServiceTest.java +++ b/src/test/java/com/lq/SysPermissionServiceTest.java @@ -1,20 +1,21 @@ package com.lq; +import com.github.jsonzou.jmockdata.JMockData; import com.lq.cms.emun.BasicsPermissionKeyEnum; import com.lq.cms.emun.StatusTypeEnum; +import com.lq.dao.SysLogDao; import com.lq.dao.SysPermissionDao; import com.lq.dao.SysResourceDao; import com.lq.dao.SysUserDao; +import com.lq.entity.SysLog; import com.lq.entity.SysPermission; import com.lq.entity.SysResource; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Map; public class SysPermissionServiceTest extends BaseTest { @@ -24,9 +25,20 @@ public class SysPermissionServiceTest extends BaseTest { private SysPermissionDao sysPermissionDao; @Autowired private SysResourceDao sysResourceDao; + @Autowired + private SysLogDao sysLogDao; @Test public void test1(){ + int length = 1; + + while (length>0){ + SysLog sysLog = JMockData.mock(SysLog.class); + sysLog.setId(null); + sysLog.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue()); + sysLogDao.save(sysLog); + length--; + } } @@ -51,7 +63,7 @@ public class SysPermissionServiceTest extends BaseTest { sysPermission.setUpdateTime(new Date()); sysPermission.setUpdateUserId(1L); // sysPermissionList.add(sysPermission); - sysPermissionDao.save(sysPermission); + // sysPermissionDao.save(sysPermission); } }); //3.权限入库 diff --git a/src/test/java/com/lq/code/dto/QueueDtoTest.java b/src/test/java/com/lq/code/dto/QueueDtoTest.java new file mode 100644 index 0000000..b3bce4c --- /dev/null +++ b/src/test/java/com/lq/code/dto/QueueDtoTest.java @@ -0,0 +1,25 @@ +package com.lq.code.dto; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class QueueDtoTest { + + @Test + public void add() { + + } + + @Test + public void pop() { + } + + @Test + public void hasNext() { + } + + @Test + public void getIndex() { + } +} \ No newline at end of file