我遇到一个问题,我的Simple AGI应用程序在保存/更新实体时挂起,并且不会抛出任何错误。从Repository中选择查询/方法按预期工作,没有任何错误。我使用Spring Boot和Spring Data JPA,它继续存在于MYSQL数据库中。
Subscriber.java:
package com.newcom.ncivr.model;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import javax.persistence.*;
@Entity @Table(name = "subscribers")
public class Subscriber{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int Id;
private String msisdn;
private String subscriptionName;
@Column(columnDefinition = "DATETIME")
private DateTime lastRenewal;
private String status;
public Subscriber() {
}
public Subscriber(String msisdn, String subscriptionName) {
this.msisdn = msisdn;
this.subscriptionName = subscriptionName;
this.lastRenewal = DateTime.now(DateTimeZone.UTC).minusDays(1);
this.status = "ACTIVE";
}
//POJO Getters and Setters Excluded from Sample
}
SubscriberRepository.java:
package com.newcom.ncivr.repository;
import com.newcom.ncivr.model.Subscriber;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SubscriberRepository extends CrudRepository<Subscriber,Integer>{
Subscriber findFirstByMsisdnAndSubscriptionNameAndStatus(String msisdn, String subscriptionName, String status);
}
IvrAgi.java:
package com.newcom.ncivr.agi;
import com.newcom.ncivr.model.Subscriber;
import com.newcom.ncivr.repository.SubscriberRepository;
import org.asteriskjava.fastagi.*;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
public class IvrAgi extends BaseAgiScript {
private Logger log = LoggerFactory.getLogger(IvrAgi.class);
@Autowired
SubscriberRepository subscriberRepository;
public void service(AgiRequest request, AgiChannel channel) throws AgiException {
log.info("********** Agi Script Started. **************");
// Answer the channel...
answer();
log.info("Caller ID: "+request.getCallerIdNumber());
mainMenu(request);
log.info("********** Agi Script Completed. **************");
}
public void mainMenu(AgiRequest request) throws AgiException {
try {
while (true) {
String data = getData("ivr_main_menu");
log.info("User Input : " + data);
if (data.equals("1")) {
System.out.println(request.getCallerIdNumber() + ": User Selected 1");
streamFile("ivr_opt_one");
log.info(request.getCallerIdNumber() + ": User Selected 1");
try {
Subscriber subscriber = subscriberRepository.findFirstByMsisdnAndSubscriptionNameAndStatus(request.getCallerIdNumber(),"NEWS", "ACTIVE");
if(subscriber != null){
log.info("Id --->" + subscriber.toString());
subscriber.setLastRenewal(DateTime.now(DateTimeZone.UTC));
subscriber = subscriberRepository.save(subscriber);
log.info("Updated Entity --> " + subscriber.toString());
}else{
log.info("User is NOT Subscribed to NEWS");
}
}catch (Exception e){
e.printStackTrace();
}
hangup();
}else{
continue;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
申请主要:
package com.newcom.ncivr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource("classpath:/asterisk/asterisk-config.xml")
public class IvrApplication {
@Autowired
public static void main(String[] args) {
SpringApplication.run(IvrApplication.class, args);
}
}
asterisk-config.xml(将Asterisk AGI映射到Spring Boot Service):
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="agiServer" class="org.asteriskjava.fastagi.DefaultAgiServer"
init-method="startup" destroy-method="shutdown">
<!--<property name="port" value="1111"/>-->
<property name="mappingStrategy" ref="mappingStrategy"/>
</bean>
<bean id="vanivr" class="com.newcom.ncivr.agi.IvrAgi">
</bean>
<bean id="mappingStrategy" class="org.asteriskjava.fastagi.SimpleMappingStrategy">
<property name="mappings">
<map>
<entry key="vanivr.agi" value-ref="vanivr"/>
</map>
</property>
</bean>
</beans>
application.properties:
#Database connection settings
spring.datasource.url=jdbc:mysql://localhost:3306/ncivr?useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.jadira.usertype.autoRegisterUserTypes = true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.type=trace
logging.level.org.hibernate=TRACE
debug=true
答案 0 :(得分:1)
我将相关信息放在下面转储中的堆栈跟踪中。
有一个线程BLOCKED
,等待锁定&lt; 0x0000000081cc7448&gt; 。如果你搜索线程转储,你会在下面包含的另一个帖子中找到第二次提到0000000081cc7448
。
该线程名为restartedMain
,它似乎与Boot Dev Tools有关,后者监视文件并在文件更改时重新启动应用程序。例如,请参阅问题@Josh's answer和评论。
我建议您删除/禁用Dev Tools,因为它们似乎涉及到问题。
"AJ DaemonPool-1.1" #258 daemon prio=5 os_prio=0 tid=0x000000001e067800 nid=0x4c0c waiting for monitor entry [0x000000002c75e000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:187)
- waiting to lock <0x0000000081cc7448> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:389)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:177)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:89)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:66)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineQualifiedTransactionManager(TransactionAspectSupport.java:382)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:363)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy70.save(Unknown Source)
at com.newcom.ncivr.agi.VanuatuIvrAgi.mainMenuOptOne(VanuatuIvrAgi.java:109)
at com.newcom.ncivr.agi.VanuatuIvrAgi.mainMenu(VanuatuIvrAgi.java:56)
at com.newcom.ncivr.agi.VanuatuIvrAgi.service(VanuatuIvrAgi.java:38)
at com.newcom.ncivr.agi.VanuatuIvrAgi$$FastClassBySpringCGLIB$$1e77fb85.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)
at com.newcom.ncivr.agi.VanuatuIvrAgi$$EnhancerBySpringCGLIB$$f6639040.service(<generated>)
at org.asteriskjava.fastagi.internal.AgiConnectionHandler.runScript(AgiConnectionHandler.java:165)
at org.asteriskjava.fastagi.internal.AgiConnectionHandler.run(AgiConnectionHandler.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
"restartedMain" #26 prio=5 os_prio=0 tid=0x000000001c4dc000 nid=0xf9c runnable [0x000000001de5d000]
java.lang.Thread.State: RUNNABLE
at java.net.DualStackPlainSocketImpl.accept0(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
- locked <0x00000000826ab858> (a java.net.SocksSocketImpl)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at org.asteriskjava.util.internal.ServerSocketFacadeImpl.accept(ServerSocketFacadeImpl.java:49)
at org.asteriskjava.fastagi.DefaultAgiServer.startup(DefaultAgiServer.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1758)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1695)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- locked <0x0000000081cc7448> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
- locked <0x0000000081cd9e08> (a java.lang.Object)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.newcom.ncivr.NcivrApplication.main(NcivrApplication.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
<强>更新强>
从您的新线程转储判断,如果没有Boot Dev Tools的帮助,这个AGI就会遇到麻烦。阻塞线程看起来与上面发布的阻塞线程非常相似。它试图通过调用DefaultAgiServer.startup
来连接到某个服务器。不确定那里有什么问题,但是可能会产生一些日志或者在很长一段时间后出现意义完全错误而失败,或者你可以调试它?也许这只是错误的连接信息?
我在谷歌搜索方法调用时发现了这个SpringBoot app starts multiple times and disconnects from logstash。
答案 1 :(得分:1)
通过使用AgiServerThread运行AgiServer来解决问题。
更新了asterisk-conf.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean class="org.asteriskjava.fastagi.AgiServerThread"
init-method="startup" destroy-method="shutdown">
<property name="agiServer" ref="agiServer"/>
</bean>
<bean id="agiServer" class="org.asteriskjava.fastagi.DefaultAgiServer">
<!--init-method="startup" destroy-method="shutdown">-->
<property name="port" value="4573"/>
<property name="mappingStrategy" ref="mappingStrategy"/>
</bean>
<bean id="vanivr" class="com.newcom.ncivr.agi.IvrAgi">
</bean>
<bean id="mappingStrategy" class="org.asteriskjava.fastagi.SimpleMappingStrategy">
<property name="mappings">
<map>
<entry key="vanivr.agi" value-ref="vanivr"/>
</map>
</property>
</bean>
</beans>