-
Notifications
You must be signed in to change notification settings - Fork 136
/
ConnectorRuntime.java
executable file
·1466 lines (1258 loc) · 57.8 KB
/
ConnectorRuntime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.enterprise.connectors;
import com.sun.appserv.connectors.internal.api.ConnectorConstants;
import com.sun.appserv.connectors.internal.api.ConnectorRuntimeException;
import com.sun.appserv.connectors.internal.api.ConnectorsClassLoaderUtil;
import com.sun.appserv.connectors.internal.api.ConnectorsUtil;
import com.sun.appserv.connectors.internal.api.WorkContextHandler;
import com.sun.appserv.connectors.internal.api.WorkManagerFactory;
import com.sun.appserv.connectors.internal.spi.ConnectorNamingEventListener;
import com.sun.enterprise.config.serverbeans.Application;
import com.sun.enterprise.config.serverbeans.Applications;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.config.serverbeans.Module;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.ResourcePool;
import com.sun.enterprise.config.serverbeans.Resources;
import com.sun.enterprise.connectors.authentication.AuthenticationService;
import com.sun.enterprise.connectors.connector.module.RarType;
import com.sun.enterprise.connectors.deployment.util.ConnectorArchivist;
import com.sun.enterprise.connectors.module.ConnectorApplication;
import com.sun.enterprise.connectors.service.ConnectorAdminObjectAdminServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorAdminServicesFactory;
import com.sun.enterprise.connectors.service.ConnectorConfigurationParserServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorConnectionPoolAdminServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorSecurityAdminServiceImpl;
import com.sun.enterprise.connectors.service.ConnectorService;
import com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl;
import com.sun.enterprise.connectors.util.ConnectorConfigParser;
import com.sun.enterprise.connectors.util.ConnectorConfigParserFactory;
import com.sun.enterprise.connectors.util.ConnectorJavaBeanValidator;
import com.sun.enterprise.connectors.util.ConnectorTimerProxy;
import com.sun.enterprise.connectors.util.DriverLoader;
import com.sun.enterprise.connectors.util.RAWriterAdapter;
import com.sun.enterprise.connectors.util.ResourcesUtil;
import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.deploy.shared.FileArchive;
import com.sun.enterprise.deployment.ConnectorDescriptor;
import com.sun.enterprise.deployment.JndiNameEnvironment;
import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
import com.sun.enterprise.deployment.archivist.ApplicationArchivist;
import com.sun.enterprise.deployment.archivist.ArchivistFactory;
import com.sun.enterprise.resource.pool.PoolManager;
import com.sun.enterprise.resource.pool.monitor.ConnectionPoolProbeProviderUtil;
import com.sun.enterprise.resource.pool.monitor.PoolMonitoringLevelListener;
import com.sun.enterprise.security.SecurityServicesUtil;
import com.sun.enterprise.security.ee.jmac.callback.ContainerCallbackHandler;
import com.sun.enterprise.transaction.api.JavaEETransactionManager;
import com.sun.logging.LogDomains;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.ResourceAdapterAssociation;
import jakarta.resource.spi.XATerminator;
import jakarta.resource.spi.work.WorkManager;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import java.io.PrintWriter;
import java.net.URI;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.security.auth.callback.CallbackHandler;
import org.glassfish.admin.monitor.MonitoringBootstrap;
import org.glassfish.api.admin.ProcessEnvironment;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.api.invocation.InvocationManager;
import org.glassfish.api.naming.GlassfishNamingManager;
import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.connectors.config.ResourceAdapterConfig;
import org.glassfish.connectors.config.SecurityMap;
import org.glassfish.connectors.config.WorkSecurityMap;
import org.glassfish.deployment.common.SecurityRoleMapperFactory;
import org.glassfish.hk2.api.PostConstruct;
import org.glassfish.hk2.api.PreDestroy;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.ClassLoaderHierarchy;
import org.glassfish.internal.api.ConnectorClassLoaderService;
import org.glassfish.internal.api.DelegatingClassLoader;
import org.glassfish.internal.data.ApplicationRegistry;
import org.glassfish.resourcebase.resources.api.PoolInfo;
import org.glassfish.resourcebase.resources.api.ResourceDeployer;
import org.glassfish.resourcebase.resources.api.ResourceInfo;
import org.glassfish.resourcebase.resources.listener.ResourceManager;
import org.glassfish.resourcebase.resources.naming.ResourceNamingService;
import org.glassfish.resourcebase.resources.util.ResourceManagerFactory;
import org.glassfish.resources.api.ResourcesRegistry;
import org.glassfish.server.ServerEnvironmentImpl;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.types.Property;
import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getApplicationNameOfEmbeddedRar;
import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.getRarNameFromApplication;
import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.isApplicationScopedResource;
import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.isModuleScopedResource;
import static com.sun.appserv.connectors.internal.api.ConnectorsUtil.isStandAloneRA;
import static com.sun.logging.LogDomains.RSR_LOGGER;
/**
* This class is the entry point to connector backend module. It exposes different API's called by external entities
* like JPA, admin to perform various connector backend related operations. It delegates calls to various connetcor
* admin services and other connector services which actually implement the functionality. This is a delegating class.
*
* @author Binod P.G, Srikanth P, Aditya Gore, Jagadish Ramu
*/
@Service
@Singleton
public class ConnectorRuntime implements com.sun.appserv.connectors.internal.api.ConnectorRuntime, PostConstruct, PreDestroy {
private static ConnectorRuntime _runtime;
private final Logger _logger = LogDomains.getLogger(ConnectorRuntime.class, RSR_LOGGER);
private ConnectorConnectionPoolAdminServiceImpl ccPoolAdmService;
private ConnectorResourceAdminServiceImpl connectorResourceAdmService;
private ConnectorService connectorService;
private ConnectorConfigurationParserServiceImpl configParserAdmService;
private ResourceAdapterAdminServiceImpl resourceAdapterAdmService;
private ConnectorSecurityAdminServiceImpl connectorSecurityAdmService;
private ConnectorAdminObjectAdminServiceImpl adminObjectAdminService;
private final ConnectorRegistry connectorRegistry = ConnectorRegistry.getInstance();
private PoolMonitoringLevelListener poolMonitoringLevelListener;
@Inject
private GlassfishNamingManager namingManager;
@Inject
private PoolManager poolManager;
@Inject
private InvocationManager invocationManager;
@Inject
private ComponentEnvManager componentEnvManager;
@Inject
private Provider<JavaEETransactionManager> javaEETransactionManagerProvider;
@Inject
private Provider<WorkManagerFactory> workManagerFactoryProvider;
@Inject
private Provider<ResourceManagerFactory> resourceManagerFactoryProvider;
@Inject
private Provider<ApplicationRegistry> applicationRegistryProvider;
@Inject
private Provider<ApplicationArchivist> applicationArchivistProvider;
@Inject
private Provider<FileArchive> fileArchiveProvider;
@Inject
private Provider<SecurityRoleMapperFactory> securityRoleMapperFactoryProvider;
@Inject
private Provider<SecurityServicesUtil> securityServicesUtilProvider;
@Inject
private Provider<ContainerCallbackHandler> containerCallbackHandlerProvider;
@Inject
private Provider<ArchivistFactory> archivistFactoryProvider;
@Inject
private Provider<WorkContextHandler> workContextHandlerProvider;
@Inject
private Provider<com.sun.enterprise.resource.deployer.MailSessionDeployer> mailSessionDeployerProvider;
@Inject
@Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
private Provider<org.glassfish.connectors.config.ConnectorService> connectorServiceProvider;
@Inject
private Provider<Applications> applicationsProvider;
@Inject
private ClassLoaderHierarchy classLoaderHierarchy;
@Inject
private ConnectorsClassLoaderUtil connectorsClassLoaderUtil;
@Inject
private ActiveRAFactory activeRAFactory;
@Inject
private Provider<ConnectionPoolProbeProviderUtil> connectionPoolProbeProviderUtilProvider;
@Inject
private Provider<MonitoringBootstrap> monitoringBootstrapProvider;
@Inject
private Provider<PoolMonitoringLevelListener> poolMonitoringLevelListenerProvider;
@Inject
private Provider<Domain> domainProvider;
@Inject
private Provider<ResourceManager> resourceManagerProvider;
/* protected for unit test */
@Inject
protected ProcessEnvironment processEnvironment;
@Inject
private DriverLoader driverLoader;
@Inject
private ConnectorJavaBeanValidator connectorBeanValidator;
@Inject
private ConnectorClassLoaderService connectorClassLoaderService;
@Inject
private ServerEnvironmentImpl serverEnvironmentImpl;
@Inject
private ResourceNamingService resourceNamingService;
@Inject
private RarType archiveType;
@Inject
private ServiceLocator serviceLocator;
private Resources globalResources;
private ResourceManager resourceManager;
// performance improvement, cache the lookup of transaction manager.
private JavaEETransactionManager transactionManager;
private ProcessEnvironment.ProcessType processType;
/**
* Returns the ConnectorRuntime instance. It follows singleton pattern and only one instance exists at any point of
* time. External entities need to call this method to get ConnectorRuntime instance
*
* @return ConnectorRuntime instance
*/
public static ConnectorRuntime getRuntime() {
if (_runtime == null) {
throw new RuntimeException("Connector Runtime not initialized");
}
return _runtime;
}
/**
* Private constructor. It is private as it follows singleton pattern.
*/
public ConnectorRuntime() {
_runtime = this;
}
public ConnectionPoolProbeProviderUtil getProbeProviderUtil() {
return connectionPoolProbeProviderUtilProvider.get();
}
public ResourceNamingService getResourceNamingService() {
return resourceNamingService;
}
/**
* Returns the execution environment.
*
* @return ConnectorConstants.SERVER if execution environment is appserv runtime else it returns
* ConnectorConstants.CLIENT
*/
@Override
public ProcessEnvironment.ProcessType getEnvironment() {
return processType;
}
public MonitoringBootstrap getMonitoringBootstrap() {
return monitoringBootstrapProvider.get();
}
/**
* Returns the generated default connection poolName for a connection definition.
*
* @param moduleName rar module name
* @param connectionDefName connection definition name
* @return generated connection poolname
*/
public SimpleJndiName getDefaultPoolName(String moduleName, String connectionDefName) {
return connectorService.getDefaultPoolName(moduleName, connectionDefName);
}
/**
* Deletes connector Connection pool
*
* @param poolInfo Name of the pool to delete
* @throws ConnectorRuntimeException if pool deletion operation fails
*/
public void deleteConnectorConnectionPool(PoolInfo poolInfo) throws ConnectorRuntimeException {
ccPoolAdmService.deleteConnectorConnectionPool(poolInfo);
}
/**
* Creates connector connection pool in the connector container.
*
* @param connectorPoolObj ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool
* properties.
* @throws ConnectorRuntimeException When creation of pool fails.
*/
public void createConnectorConnectionPool(ConnectorConnectionPool connectorPoolObj) throws ConnectorRuntimeException {
ccPoolAdmService.createConnectorConnectionPool(connectorPoolObj);
}
/**
* Creates the connector resource on a given connection pool
*
* @param resourceInfo JNDI name of the resource to be created
* @param poolInfo to which the connector resource belongs.
* @param resourceType Unused.
* @throws ConnectorRuntimeException If the resouce creation fails.
*/
public void createConnectorResource(ResourceInfo resourceInfo, PoolInfo poolInfo, String resourceType) throws ConnectorRuntimeException {
connectorResourceAdmService.createConnectorResource(resourceInfo, poolInfo, resourceType);
}
/**
* Returns the generated default connector resource for a connection definition.
*
* @param moduleName rar module name
* @param connectionDefName connection definition name
* @return generated default connector resource name
*/
public SimpleJndiName getDefaultResourceName(String moduleName, String connectionDefName) {
return connectorService.getDefaultResourceName(moduleName, connectionDefName);
}
/**
* Provides resource adapter log writer to be given to MCF of a resource-adapter
*
* @return PrintWriter
*/
public PrintWriter getResourceAdapterLogWriter() {
Logger logger = LogDomains.getLogger(ConnectorRuntime.class, LogDomains.RSR_LOGGER);
return new PrintWriter(new RAWriterAdapter(logger));
}
/**
* Deletes the connector resource.
*
* @param resourceInfo JNDI name of the resource to delete.
* @throws ConnectorRuntimeException if connector resource deletion fails.
*/
public void deleteConnectorResource(ResourceInfo resourceInfo) throws ConnectorRuntimeException {
connectorResourceAdmService.deleteConnectorResource(resourceInfo);
}
/**
* Obtains the connector Descriptor pertaining to rar. If ConnectorDescriptor is present in registry, it is obtained
* from registry and returned. Else it is explicitly read from directory where rar is exploded.
*
* @param rarName Name of the rar
* @return ConnectorDescriptor pertaining to rar.
* @throws ConnectorRuntimeException when unable to get descriptor
*/
@Override
public ConnectorDescriptor getConnectorDescriptor(String rarName) throws ConnectorRuntimeException {
return connectorService.getConnectorDescriptor(rarName);
}
/**
* {@inheritDoc}
*/
@Override
public void createActiveResourceAdapter(String moduleDir, String moduleName, ClassLoader loader) throws ConnectorRuntimeException {
resourceAdapterAdmService.createActiveResourceAdapter(moduleDir, moduleName, loader);
}
/**
* {@inheritDoc}
*/
public void createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, String moduleName, String moduleDir, ClassLoader loader) throws ConnectorRuntimeException {
resourceAdapterAdmService.createActiveResourceAdapter(connectorDescriptor, moduleName, moduleDir, loader);
}
/**
* Creates Active resource Adapter which abstracts the rar module. During the creation of ActiveResourceAdapter, default
* pools and resources also are created.
*
* @param connectorDescriptor object which abstracts the connector deployment descriptor i.e rar.xml and sun-ra.xml.
* @param moduleName Name of the module
* @param moduleDir Directory where rar module is exploded.
* @throws ConnectorRuntimeException if creation fails.
*/
public void createActiveResourceAdapter(ConnectorDescriptor connectorDescriptor, String moduleName, String moduleDir) throws ConnectorRuntimeException {
resourceAdapterAdmService.createActiveResourceAdapter(connectorDescriptor, moduleName, moduleDir, null);
}
/**
* {@inheritDoc}
*/
@Override
public void destroyActiveResourceAdapter(String moduleName) throws ConnectorRuntimeException {
resourceAdapterAdmService.stopActiveResourceAdapter(moduleName);
}
/**
* Returns the MCF instance. If the MCF is already created and present in connectorRegistry that instance is returned.
* Otherwise it is created explicitly and added to ConnectorRegistry.
*
* @param poolInfo Name of the pool.MCF pertaining to this pool is created/returned.
* @return created/already present MCF instance
* @throws ConnectorRuntimeException if creation/retrieval of MCF fails
*/
@Override
public ManagedConnectionFactory obtainManagedConnectionFactory(PoolInfo poolInfo) throws ConnectorRuntimeException {
return ccPoolAdmService.obtainManagedConnectionFactory(poolInfo);
}
/**
* Returns the MCF instance. If the MCF is already created and present in connectorRegistry that instance is returned.
* Otherwise it is created explicitly and added to ConnectorRegistry.
*
* @param poolInfo Name of the pool.MCF pertaining to this pool is created/returned.
* @return created/already present MCF instance
* @throws ConnectorRuntimeException if creation/retrieval of MCF fails
*/
@Override
public ManagedConnectionFactory obtainManagedConnectionFactory(PoolInfo poolInfo, Hashtable env) throws ConnectorRuntimeException {
return ccPoolAdmService.obtainManagedConnectionFactory(poolInfo, env);
}
/**
* Returns the MCF instances in scenarions where a pool has to return multiple mcfs. Should be used only during JMS RA
* recovery.
*
* @param poolInfo Name of the pool.MCFs pertaining to this pool is created/returned.
* @return created MCF instances
* @throws ConnectorRuntimeException if creation/retrieval of MCFs fails
*/
public ManagedConnectionFactory[] obtainManagedConnectionFactories(PoolInfo poolInfo) throws ConnectorRuntimeException {
return ccPoolAdmService.obtainManagedConnectionFactories(poolInfo);
}
/**
* provides connection manager for a pool
*
* @param poolInfo pool name
* @param forceNoLazyAssoc when set to true, lazy association feature will be turned off (even if it is ON via pool
* attribute)
* @return ConnectionManager for the pool
* @throws ConnectorRuntimeException when unable to provide a connection manager
*/
public ConnectionManager obtainConnectionManager(PoolInfo poolInfo, boolean forceNoLazyAssoc, ResourceInfo resourceInfo) throws ConnectorRuntimeException {
return ConnectionManagerFactory.getAvailableConnectionManager(poolInfo, forceNoLazyAssoc, resourceInfo);
}
@Override
public <T> T lookupPMResource(ResourceInfo resourceInfo, boolean force) throws NamingException{
final ResourceInfo ri;
if (resourceInfo.getName().hasSuffix(PM_JNDI_SUFFIX)) {
ri = resourceInfo;
} else {
SimpleJndiName jndiName = SimpleJndiName.of(resourceInfo.getName() + PM_JNDI_SUFFIX);
ri = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
try {
return connectorResourceAdmService.lookup(ri);
} catch (NamingException ne) {
if (force && isDAS()) {
_logger.log(Level.FINE, "jdbc.unable_to_lookup_resource", ri);
return lookupDataSourceInDAS(ri);
}
throw ne;
}
}
@Override
public <T> T lookupPMResource(SimpleJndiName jndiName, boolean force) throws NamingException {
ResourceInfo resourceInfo = new ResourceInfo(jndiName);
return lookupPMResource(resourceInfo, force);
}
@Override
public <T> T lookupNonTxResource(SimpleJndiName jndiName, boolean force) throws NamingException {
ResourceInfo resourceInfo = new ResourceInfo(jndiName);
return lookupNonTxResource(resourceInfo, force);
}
@Override
public <T> T lookupNonTxResource(ResourceInfo resourceInfo, boolean force) throws NamingException {
final ResourceInfo ri;
if (resourceInfo.getName().hasSuffix(NON_TX_JNDI_SUFFIX)) {
ri = resourceInfo;
} else {
SimpleJndiName jndiName = SimpleJndiName.of(resourceInfo.getName() + NON_TX_JNDI_SUFFIX);
ri = new ResourceInfo(jndiName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
try {
return connectorResourceAdmService.lookup(ri);
} catch (NamingException ne) {
if (force && isDAS()) {
_logger.log(Level.FINE, "jdbc.unable_to_lookup_resource", ri);
return lookupDataSourceInDAS(ri);
}
throw ne;
}
}
private boolean isDAS() {
return serverEnvironmentImpl.isDas();
}
/**
* Get a wrapper datasource specified by the jdbcjndi name This API is intended to be used in the DAS. The motivation
* for having this API is to provide the CMP backend/ JPA-Java2DB a means of acquiring a connection during the codegen
* phase. If a user is trying to deploy an JPA-Java2DB app on a remote server, without this API, a resource reference
* has to be present both in the DAS and the server instance. This makes the deployment more complex for the user since
* a resource needs to be forcibly created in the DAS Too. This API will mitigate this need.
*
* @param resourceInfo jndi name of the resource
* @return DataSource representing the resource.
*/
private <T> T lookupDataSourceInDAS(ResourceInfo resourceInfo) {
try {
Collection<ConnectorRuntimeExtension> extensions = serviceLocator
.getAllServices(ConnectorRuntimeExtension.class);
for (ConnectorRuntimeExtension extension : extensions) {
return extension.lookupDataSourceInDAS(resourceInfo);
}
return null;
} catch (ConnectorRuntimeException cre) {
throw new RuntimeException(cre.getMessage(), cre);
}
}
/**
* Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS.
* The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen
* phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be
* present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource
* needs to be forcibly created in the DAS Too. This API will mitigate this need.
*
* @param resourceInfo the jndi name of the resource being used to get Connection from This resource can either be a pmf
* resource or a jdbc resource
* @param user the user used to authenticate this request
* @param password the password used to authenticate this request
*
* @return a java.sql.Connection
* @throws java.sql.SQLException in case of errors
*/
public Connection getConnection(ResourceInfo resourceInfo, String user, String password) throws SQLException {
return ccPoolAdmService.getConnection(resourceInfo, user, password);
}
/**
* Get a sql connection from the DataSource specified by the jdbcJndiName. This API is intended to be used in the DAS.
* The motivation for having this API is to provide the CMP backend a means of acquiring a connection during the codegen
* phase. If a user is trying to deploy an app on a remote server, without this API, a resource reference has to be
* present both in the DAS and the server instance. This makes the deployment more complex for the user since a resource
* needs to be forcibly created in the DAS Too. This API will mitigate this need.
*
* @param resourceInfo the jndi name of the resource being used to get Connection from This resource can either be a pmf
* resource or a jdbc resource
*
* @return a java.sql.Connection
* @throws java.sql.SQLException in case of errors
*/
public Connection getConnection(ResourceInfo resourceInfo) throws SQLException {
return ccPoolAdmService.getConnection(resourceInfo);
}
/**
* Gets the properties of the Java bean connection definition class that have setter methods defined and the default
* values as provided by the Connection Definition java bean developer. This method is used to get properties of
* jdbc-data-source<br>
* To get Connection definition properties for Connector Connection Pool, use
* ConnectorRuntime.getMCFConfigProperties()<br>
* When the connection definition class is not found, standard JDBC properties (of JDBC 3.0 Specification) will be
* returned.<br>
*
* @param connectionDefinitionClassName The Connection Definition Java bean class for which overrideable properties are
* required.
* @return Map<String, Object> String represents property name and Object is the defaultValue that is a primitive type
* or String.
*/
@Override
public Map<String, Object> getConnectionDefinitionPropertiesAndDefaults(String connectionDefinitionClassName, String resType) {
return ConnectorConnectionPoolAdminServiceImpl.getConnectionDefinitionPropertiesAndDefaults(connectionDefinitionClassName, resType);
}
/**
* Provides the list of built in custom resources by resource-type and factory-class-name pair.
*
* @return map of resource-type & factory-class-name
*/
@Override
public Map<String, String> getBuiltInCustomResources() {
return ConnectorsUtil.getBuiltInCustomResources();
}
@Override
public String[] getSystemConnectorsAllowingPoolCreation() {
Collection<String> validSystemRarsAllowingPoolCreation = new ArrayList<>();
Collection<String> validSystemRars = ConnectorsUtil.getSystemRARs();
for (String systemRarName : systemRarsAllowingPoolCreation) {
if (validSystemRars.contains(systemRarName)) {
validSystemRarsAllowingPoolCreation.add(systemRarName);
}
}
return validSystemRarsAllowingPoolCreation.toArray(new String[validSystemRarsAllowingPoolCreation.size()]);
}
@Override
public String[] getConnectionDefinitionNames(String rarName) throws ConnectorRuntimeException {
return configParserAdmService.getConnectionDefinitionNames(rarName);
}
@Override
public String getSecurityPermissionSpec(String moduleName) throws ConnectorRuntimeException {
return configParserAdmService.getSecurityPermissionSpec(moduleName);
}
@Override
public String[] getAdminObjectInterfaceNames(String rarName) throws ConnectorRuntimeException {
return configParserAdmService.getAdminObjectInterfaceNames(rarName);
}
@Override
public String[] getAdminObjectClassNames(String rarName, String intfName) throws ConnectorRuntimeException {
return configParserAdmService.getAdminObjectClassNames(rarName, intfName);
}
@Override
public boolean hasAdminObject(String rarName, String intfName, String className) throws ConnectorRuntimeException {
return configParserAdmService.hasAdminObject(rarName, intfName, className);
}
@Override
public Map<String, String> getResourceAdapterConfigProps(String rarName) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getResourceAdapterConfigProps(rarName);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public Map<String, String> getMCFConfigProps(String rarName, String connectionDefName) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getMCFConfigProps(rarName, connectionDefName);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public Map<String, String> getAdminObjectConfigProps(String rarName, String adminObjectIntf) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getAdminObjectConfigProps(rarName, adminObjectIntf);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public Map<String, String> getAdminObjectConfigProps(String rarName, String adminObjectIntf, String adminObjectClass) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getAdminObjectConfigProps(rarName, adminObjectIntf, adminObjectClass);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public Map<String, String> getConnectorConfigJavaBeans(String rarName, String connectionDefName, String type) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getConnectorConfigJavaBeans(rarName, connectionDefName, type);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public String getActivationSpecClass(String rarName, String messageListenerType) throws ConnectorRuntimeException {
return configParserAdmService.getActivationSpecClass(rarName, messageListenerType);
}
@Override
public String[] getMessageListenerTypes(String rarName) throws ConnectorRuntimeException {
return configParserAdmService.getMessageListenerTypes(rarName);
}
@Override
public Map<String, String> getMessageListenerConfigProps(String rarName, String messageListenerType) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getMessageListenerConfigProps(rarName, messageListenerType);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
@Override
public Map<String, String> getMessageListenerConfigPropTypes(String rarName, String messageListenerType) throws ConnectorRuntimeException {
Properties properties = configParserAdmService.getMessageListenerConfigPropTypes(rarName, messageListenerType);
return ConnectorsUtil.convertPropertiesToMap(properties);
}
/**
* Causes pool to switch on the matching of connections. It can be either directly on the pool or on the
* ConnectorConnectionPool object that is bound in JNDI.
*
* @param rarName Name of Resource Adpater.
* @param poolInfo Name of the pool.
*/
public void switchOnMatching(String rarName, PoolInfo poolInfo) {
connectorService.switchOnMatching(rarName, poolInfo);
}
/**
* Causes matching to be switched on the ConnectorConnectionPool bound in JNDI
*
* @param poolInfo Name of the pool
* @throws ConnectorRuntimeException when unable to set matching via jndi object
*/
public void switchOnMatchingInJndi(PoolInfo poolInfo) throws ConnectorRuntimeException {
ccPoolAdmService.switchOnMatching(poolInfo);
}
public GlassfishNamingManager getNamingManager() {
return namingManager;
}
/**
* The component has been injected with any dependency and will be placed into commission by the subsystem.
*/
@Override
public void postConstruct() {
ccPoolAdmService = (ConnectorConnectionPoolAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.CCP);
connectorResourceAdmService = (ConnectorResourceAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.CR);
connectorService = new ConnectorService();
resourceAdapterAdmService = (ResourceAdapterAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.RA);
connectorSecurityAdmService = (ConnectorSecurityAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.SEC);
adminObjectAdminService = (ConnectorAdminObjectAdminServiceImpl) ConnectorAdminServicesFactory.getService(ConnectorConstants.AOR);
configParserAdmService = new ConnectorConfigurationParserServiceImpl();
initializeEnvironment(processEnvironment);
if (isServer()) {
getProbeProviderUtil().registerProbeProvider();
}
if (isServer() || isEmbedded()) {
poolMonitoringLevelListener = poolMonitoringLevelListenerProvider.get();
// Force initialization of the ResourceManager
getResourceManager();
}
}
/**
* initializes the connector runtime mode to be SERVER or CLIENT
*
* @param processEnvironment ProcessEnvironment
*/
private void initializeEnvironment(ProcessEnvironment processEnvironment) {
processType = processEnvironment.getProcessType();
}
/**
* Checks if a conncetor connection pool has been deployed to this server instance
*
* @param poolInfo connection pool name
* @return boolean indicating whether the resource is deployed or not
*/
public boolean isConnectorConnectionPoolDeployed(PoolInfo poolInfo) {
return ccPoolAdmService.isConnectorConnectionPoolDeployed(poolInfo);
}
/**
* Reconfigure a connection pool. This method compares the passed connector connection pool with the one in memory. If
* the pools are unequal and the MCF properties are changed a pool recreate is required. However if the pools are
* unequal and the MCF properties are not changed a recreate is not required
*
* @param ccp - the Updated connector connection pool object that admin hands over
* @param excludedProps - A set of excluded property names that we want to be excluded in the comparison check while
* comparing MCF properties
* @return true - if a pool restart is required, false otherwise
* @throws ConnectorRuntimeException when unable to reconfigure ccp
*/
public boolean reconfigureConnectorConnectionPool(ConnectorConnectionPool ccp, Set excludedProps) throws ConnectorRuntimeException {
return ccPoolAdmService.reconfigureConnectorConnectionPool(ccp, excludedProps);
}
/**
* Recreate a connector connection pool. This method essentially does the following things: 1. Delete the said connector
* connection pool<br>
* 2. Bind the pool to JNDI<br>
* 3. Create an MCF for this pool and register with the connector registry<br>
*
* @param ccp - the ConnectorConnectionPool to publish
* @throws ConnectorRuntimeException when unable to recreate ccp
*/
public void recreateConnectorConnectionPool(ConnectorConnectionPool ccp) throws ConnectorRuntimeException {
ccPoolAdmService.recreateConnectorConnectionPool(ccp);
}
/**
* Creates connector connection pool in the connector container.
*
* @param ccp ConnectorConnectionPool instance to be bound to JNDI. This object contains the pool properties.
* @param connectionDefinitionName Connection definition name against which connection pool is being created
* @param rarName Name of the resource adapter
* @param props Properties of MCF which are present in domain.xml These properties override the ones present in ra.xml
* @param securityMaps Array fo security maps.
* @throws ConnectorRuntimeException When creation of pool fails.
*/
public void createConnectorConnectionPool(ConnectorConnectionPool ccp, String connectionDefinitionName, String rarName,
List<Property> props, List<SecurityMap> securityMaps) throws ConnectorRuntimeException {
ccPoolAdmService.createConnectorConnectionPool(ccp, connectionDefinitionName, rarName, props, securityMaps);
}
private synchronized org.glassfish.resourcebase.resources.listener.ResourceManager getResourceManager() {
if (resourceManager == null) {
try {
resourceManager = resourceManagerProvider.get();
} catch (Exception e) {
return null;
}
}
return resourceManager;
}
@Override
public void cleanUpResourcesAndShutdownAllActiveRAs() {
Domain domain = domainProvider.get();
if (domain != null) {
org.glassfish.resourcebase.resources.listener.ResourceManager rm = getResourceManager();
if (rm != null) {
Collection<Resource> resources = ConnectorsUtil.getAllSystemRAResourcesAndPools(domain.getResources());
resourceManager.undeployResources(resources);
resources = null;
Collection<ConnectorRuntimeExtension> extensions = serviceLocator.getAllServices(ConnectorRuntimeExtension.class);
for (ConnectorRuntimeExtension extension : extensions) {
resources = extension.getAllSystemRAResourcesAndPools();
resourceManager.undeployResources(resources);
}
}
}
poolManager.killFreeConnectionsInPools();
resourceAdapterAdmService.stopAllActiveResourceAdapters();
}
@Override
public void shutdownAllActiveResourceAdapters() {
resourceAdapterAdmService.stopAllActiveResourceAdapters();
}
public PoolManager getPoolManager() {
return poolManager;
}
/**
* provides the invocationManager
*
* @return InvocationManager
*/
@Override
public InvocationManager getInvocationManager() {
return invocationManager;
}
public Timer getTimer() {
return ConnectorTimerProxy.getProxy();
}
/**
* get resource reference descriptors from current component's jndi environment
*
* @return set of resource-refs
*/
@Override
public Set<ResourceReferenceDescriptor> getResourceReferenceDescriptor() {
JndiNameEnvironment jndiEnv = componentEnvManager.getCurrentJndiNameEnvironment();
return jndiEnv == null ? null : jndiEnv.getResourceReferenceDescriptors();
}
/**
* The component is about to be removed from commission
*/
@Override
public void preDestroy() {
}
/**
* Obtain the authentication service associated with rar module. Currently only the BasicPassword authentication is
* supported.
*
* @param rarName Rar module Name
* @param poolInfo Name of the pool. Used for creation of BasicPasswordAuthenticationService
* @return AuthenticationService connector runtime's authentication service
*/
public AuthenticationService getAuthenticationService(String rarName, PoolInfo poolInfo) {
return connectorSecurityAdmService.getAuthenticationService(rarName, poolInfo);
}
/**
* Checks whether the executing environment is embedded
*
* @return true if execution environment is embedded
*/
@Override
public boolean isEmbedded() {
return ProcessEnvironment.ProcessType.Embedded.equals(processType);
}
/**
* Checks whether the executing environment is non-acc (standalone)
*
* @return true if execution environment is non-acc (standalone)
*/
public boolean isNonACCRuntime() {
return ProcessEnvironment.ProcessType.Other.equals(processType);
}
/**
* Checks whether the executing environment is application server
*
* @return true if execution environment is server false if it is client
*/
@Override
public boolean isServer() {
return ProcessEnvironment.ProcessType.Server.equals(processType);
}
/**
* Checks whether the executing environment is appclient container runtime
*
* @return true if execution environment is appclient container false if it is not ACC
*/
public boolean isACCRuntime() {
return ProcessEnvironment.ProcessType.ACC.equals(processType);
}
/**
* provides the current transaction
*
* @return Transaction
* @throws SystemException when unable to get the transaction
*/
public Transaction getTransaction() throws SystemException {
return getTransactionManager().getTransaction();
}
/**
* provides the transactionManager
*
* @return TransactionManager
*/
@Override
public JavaEETransactionManager getTransactionManager() {
if (transactionManager == null) {
transactionManager = javaEETransactionManagerProvider.get();
}
return transactionManager;
}
/**
* register the connector naming event listener
*
* @param listener connector-naming-event-listener
*/
@Override
public void registerConnectorNamingEventListener(ConnectorNamingEventListener listener) {