Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 动态可创建的资源适配器_Java_Wildfly 10_Jca_Ironjacamar - Fatal编程技术网

Java 动态可创建的资源适配器

Java 动态可创建的资源适配器,java,wildfly-10,jca,ironjacamar,Java,Wildfly 10,Jca,Ironjacamar,我们当前实现的JCA TCP/IP适配器需要重新评估,项目负责人向我传递了一个新的但重要的需求 需要添加新的TCP连接并在不重新启动服务器的情况下启动它们。(另外修改现有的) 目前,只有在standalone.xml中添加一个新属性时才有可能,这需要重新启动/重新加载服务器 我看了很多关于用MDB实现JCA的博客文章和“教程”,我想我已经掌握了诀窍,但我看不到一种动态地(最好是通过代码)创建新连接的方法 我曾一度认为可以将ActivationSpec与ResourceAdapter类结合使用,但

我们当前实现的JCA TCP/IP适配器需要重新评估,项目负责人向我传递了一个新的但重要的需求

需要添加新的TCP连接并在不重新启动服务器的情况下启动它们。(另外修改现有的) 目前,只有在standalone.xml中添加一个新属性时才有可能,这需要重新启动/重新加载服务器

我看了很多关于用MDB实现JCA的博客文章和“教程”,我想我已经掌握了诀窍,但我看不到一种动态地(最好是通过代码)创建新连接的方法

我曾一度认为可以将ActivationSpec与ResourceAdapter类结合使用,但我不知道这是如何实现的

编辑: 我们的资源适配器的实现完全不正确,但我仍然将其声明为双向的。它既可以侦听连接,也可以打开连接,还可以接收和发送消息

资源适配器作为解压的.rar添加到wildfly模块系统中,其中包含module.xml

C:\wildfly-10.0.0.Final\modules\com\company\server\TcpConnectorServerModule\5.1.0.0
module.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.company.server.TcpConnectorServerModule"
  slot="5.1.0.0">
  <resources>
    <resource-root path="." />
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.resource.api"/>
  </dependencies>
</module>

standalone.xml中的内容:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
            <global-modules>
                <module name="org.infinispan.cdi.embedded" slot="ispn-8.2"/>
                <module name="org.jgroups" slot="ispn-8.2"/>
                <module name="com.company.server.TcpConnectorServerModule" slot="5.1.0.0" meta-inf="true"/>
            </global-modules>

TL;医生:

是否有可能设计一个JCA资源适配器,以便在不重新启动服务器的情况下动态(希望是通过代码)创建和修改连接


如果不在JCA中重新启动是不可能的,我希望能够在Wildfly中启用TCP/IP连接到外部设备(打印机、扫描仪、电子秤等)。我们需要能够在业务逻辑中与这些设备交互。

有一个名为的热部署功能,并描述了第二个场景。在您在生产环境中进行测试之前,我将首先收集有关此功能的测试环境经验。一年前,我写了一个资源适配器测试项目,并在上用一些关于创建和使用的额外资源对其进行了描述。我希望这会有所帮助。

我发现,虽然CLI无法添加新连接,但因为我只能重新启动整个服务器,而不能重新启动子系统,所以JMX也可以

我可以添加与JMX的新连接,并通过“激活”操作“重新启动”子系统。如果子系统已处于活动状态,则该操作的作用类似于重新启动

之后,我可以像以前一样使用应用程序中的
InitialConext.listBindings()
函数获得新连接

下面是一个使用Groovy的JMX脚本示例:

import java.lang.management.ManagementFactory;
import javax.management.ObjectName;
import java.lang.String;
import java.lang.Integer;
import java.lang.Boolean;
import java.lang.Long;
import javax.management.openmbean.TabularData;
import javax.management.MBeanInfo;

def mBeanServer = ManagementFactory.getPlatformMBeanServer()

def tcpConnectorMBean = new ObjectName("jboss.as:subsystem=resource-adapters,resource-adapter=TCPConnector")
def definitionMBean = new ObjectName( "jboss.as:subsystem=resource-adapters,resource-adapter=TCPConnector,connection-definitions=*" )


println 'before test creation:'
printAvailableBeans(mBeanServer,definitionMBean, 'jndiName')

//createTcpConnection(mBeanServer,tcpConnectorMBean)

//println 'After test creation:'
//printAvailableBeans(mBeanServer,definitionMBean, 'jndiName')

/* 
* After adding a new Connection and configuring the needed properties, the Resource Adapter needs to be (re)activated in order to register
* the newly added connection and make it available with the JNDI
*/
//activateBean(mBeanServer,tcpConnectorMBean)

/**
* This function retrieves the Object for the given name and tries to retrieve all MBeans for it and extracts some information of it.
*/
void printAvailableBeans(def mBeanServer, ObjectName objectName, String attribute){

    mBeanServer.queryMBeans( objectName, null ).each {
        print 'Class name: ' + it.className
        print 'Object name : ' + it.name
        print ' -> '
        def handler = mBeanServer.getAttribute( it.name,attribute )
        println handler
    }

    println ''

}

void createTcpConnection(def mBeanServer,ObjectName objectName){

    final String name = 'TestJMX'
    final Integer allocationRetry = null
    final Long allocationRertyWaitMills = null
    final Boolean backgroundValidation = null
    final Long backgroundValidationMills = null
    final Long blockingTimeoutWaitMills = null
    final String capacityDecrementerClass = null
    final TabularData capacityDecrementerProperties = null
    final String capacityIncrementerClass = null
    final TabularData capacityIncrementerProperties = null
    final String className = 'TCPManagedConnectionFactory'
    final Boolean connectable = false
    final Boolean enabled = true
    final Boolean enlistment = true
    final Boolean enlistmentTrace = null
    final String flushStrategy = 'FailingConnectionOnly'
    final Long idleTimeoutMinutes = null
    final Integer initialPoolSize = null
    final Boolean interleaving = false
    final String jndiName = 'java:/tcp/TestJMX'
    final Integer maxPoolSize = 20
    final String mcp = null
    final Integer minPoolSize = 0
    final Boolean noRecovery = false
    final Boolean noTxSeparatePool = false
    final Boolean padXid = false
    final Boolean poolFair = true
    final Boolean poolPrefill = false
    final Boolean poolUseStrictMin = false
    final String recoveryPassword = null
    final String recoveryPluginClassName = null
    final TabularData recoveryPluginProperties = null
  final String recoverySecurityDomain = null
    final String recoveryUsername = null
    final Boolean sameRmOverride = null
    final Boolean securityApplication = false
    final String securityDomain = null
    final String securityDomainAndApplication = null
    final Boolean sharable = true
    final Boolean tracking = null
    final Boolean useCcm = true
    final Boolean useFastFail = false
    final Boolean useJavaContext = true
    final Boolean validateOnMatch = null
    final Boolean wrapXaResource = true
    final Integer xaResourceTimeout = null


    Object[] opParam =[name,allocationRetry,allocationRertyWaitMills,backgroundValidation,backgroundValidationMills,blockingTimeoutWaitMills,capacityDecrementerClass,capacityDecrementerProperties,capacityIncrementerClass,capacityIncrementerProperties,className,connectable,enabled,enlistment,enlistmentTrace,flushStrategy,idleTimeoutMinutes,initialPoolSize,interleaving,jndiName,maxPoolSize,mcp,minPoolSize,noRecovery,noTxSeparatePool,padXid,poolFair,poolPrefill,poolUseStrictMin,recoveryPassword,recoveryPluginClassName,recoveryPluginProperties,recoverySecurityDomain,recoveryUsername,sameRmOverride,securityApplication,securityDomain,securityDomainAndApplication,sharable,tracking,useCcm,useFastFail,useJavaContext,validateOnMatch,wrapXaResource,xaResourceTimeout]

    String[] opSig = [name.getClass().getName(),allocationRetry.getClass().getName(),allocationRertyWaitMills.getClass().getName(),backgroundValidation.getClass().getName(),backgroundValidationMills.getClass().getName(),blockingTimeoutWaitMills.getClass().getName(),capacityDecrementerClass.getClass().getName(),capacityDecrementerProperties.getClass().getName(),capacityIncrementerClass.getClass().getName(),capacityIncrementerProperties.getClass().getName(),className.getClass().getName(),connectable.getClass().getName(),enabled.getClass().getName(),enlistment.getClass().getName(),enlistmentTrace.getClass().getName(),flushStrategy.getClass().getName(),idleTimeoutMinutes.getClass().getName(),initialPoolSize.getClass().getName(),interleaving.getClass().getName(),jndiName.getClass().getName(),maxPoolSize.getClass().getName(),mcp.getClass().getName(),minPoolSize.getClass().getName(),noRecovery.getClass().getName(),noTxSeparatePool.getClass().getName(),padXid.getClass().getName(),poolFair.getClass().getName(),poolPrefill.getClass().getName(),poolUseStrictMin.getClass().getName(),recoveryPassword.getClass().getName(),recoveryPluginClassName.getClass().getName(),recoveryPluginProperties.getClass().getName(),recoverySecurityDomain.getClass().getName(),recoveryUsername.getClass().getName(),sameRmOverride.getClass().getName(),securityApplication.getClass().getName(),securityDomain.getClass().getName(),securityDomainAndApplication.getClass().getName(),sharable.getClass().getName(),tracking.getClass().getName(),useCcm.getClass().getName(),useFastFail.getClass().getName(),useJavaContext.getClass().getName(),validateOnMatch.getClass().getName(),wrapXaResource.getClass().getName(),xaResourceTimeout.getClass().getName()]

    mBeanServer.invoke(objectName,'addConnectionDefinitions',opParam,opSig)
}

void activateBean(def mBeanServer, ObjectName mBean){
    Object[] opParam = []
    String[] opSig = []

    mBeanServer.invoke(mBean, 'activate', opParam, opSig)
}

return

它是什么类型的资源适配器?入站、出站还是双向?resourceadapter是ear归档的一部分还是单个rar归档?我更新了我的问题,提供了更多详细信息,以回答您的问题@JochenBuchholz。虽然我不知道该怎么说它是什么类型的资源适配器。它是一个使用javax资源api:1.7的资源适配器,我猜它是IronJacamar,因为它包含在Wildfly中。