Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,16 +27,14 @@
import com.sun.enterprise.connectors.DeferredResourceConfig;
import com.sun.enterprise.connectors.util.ResourcesUtil;
import com.sun.enterprise.deployment.Application;
import com.sun.logging.LogDomains;

import jakarta.inject.Inject;
import jakarta.inject.Provider;

import java.lang.System.Logger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.jdbc.config.JdbcConnectionPool;
Expand All @@ -50,13 +48,16 @@
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.config.ConfigBeanProxy;

import static java.lang.System.Logger.Level.DEBUG;


/**
* @author Shalini M
*/
@Service
public class JdbcRuntimeExtension implements ConnectorRuntimeExtension {

private static final Logger LOG = LogDomains.getLogger(JdbcRuntimeExtension.class, LogDomains.RSR_LOGGER);
private static final Logger LOG = System.getLogger(JdbcRuntimeExtension.class.getName());

@Inject
private Provider<Domain> domainProvider;
Expand Down Expand Up @@ -87,7 +88,7 @@ public Collection<Resource> getAllSystemRAResourcesAndPools() {
}
}

System.out.println("JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = " + resources);
LOG.log(DEBUG, "Detected resources: {0}", resources);
return resources;
}

Expand Down Expand Up @@ -143,18 +144,12 @@ public PoolInfo getPoolNameFromResourceJndiName(ResourceInfo resourceInfo) {
}
jdbcResource = runtime.getResources(actualResourceInfo).getResourceByName(JdbcResource.class,
actualResourceInfo.getName());

if (jdbcResource != null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("jdbcRes is ---: " + jdbcResource.getJndiName());
LOG.fine("poolName is ---: " + jdbcResource.getPoolName());
}
}
if (jdbcResource != null) {
SimpleJndiName poolName = new SimpleJndiName(jdbcResource.getPoolName());
return new PoolInfo(poolName, actualResourceInfo.getApplicationName(), actualResourceInfo.getModuleName());
if (jdbcResource == null) {
return null;
}
return null;
LOG.log(DEBUG, "JDBC resource: {0} uses pool {1}", jdbcResource.getJndiName(), jdbcResource.getPoolName());
SimpleJndiName poolName = new SimpleJndiName(jdbcResource.getPoolName());
return new PoolInfo(poolName, actualResourceInfo.getApplicationName(), actualResourceInfo.getModuleName());
}

/**
Expand All @@ -176,12 +171,12 @@ public boolean isConnectionPoolReferredInServerInstance(PoolInfo poolInfo) {
ResourcesUtil resourcesUtil = ResourcesUtil.createInstance();
if (resource.getPoolName().equals(poolInfo.getName().toString())
&& resourcesUtil.isReferenced(resourceInfo) && resourcesUtil.isEnabled(resource)) {
LOG.log(Level.CONFIG, "JDBC pool {0} is referred by resource {1} and is enabled on this server",
new Object[] {poolInfo, resourceInfo});
LOG.log(DEBUG, "JDBC pool {0} is referred by resource {1} and is enabled on this server", poolInfo,
resourceInfo);
return true;
}
}
LOG.log(Level.FINE, "No JDBC resource refers [{0}] in this server instance", poolInfo);
LOG.log(DEBUG, "No JDBC resource refers {0} in this server instance", poolInfo);
return false;
}

Expand All @@ -198,27 +193,21 @@ public String getResourceType(ConfigBeanProxy cb) {
@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName)
throws ConnectorRuntimeException {
String resourceAdapterName;
DeferredResourceConfig resConfig = null;
// TODO V3 there should not be res-type related check, refactor
// deferred-ra-config
// TODO V3 (not to hold specific resource types)
if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {

JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
JdbcResource jdbcResource = (JdbcResource) resource;

resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
var resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
var resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);

resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);

Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
Resource[] resourcesToload = new Resource[] {jdbcPool, jdbcResource};
resConfig.setResourcesToLoad(resourcesToload);

} else {
throw new ConnectorRuntimeException("unsupported resource type : " + resource);
return resConfig;
}
return resConfig;
throw new ConnectorRuntimeException("unsupported resource type : " + resource);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -23,6 +24,8 @@
*/
public class GlassFishException extends Exception {

private static final long serialVersionUID = 5879674257983677584L;

public GlassFishException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ public synchronized void shutdown() throws GlassFishException {
for (GlassFish glassFish : glassFishInstances.values()) {
try {
glassFish.dispose();
} catch (IllegalStateException ex) {
LOG.log(FINER, "GlassFish dispose failed: " + ex.getMessage());
} catch (IllegalStateException e) {
LOG.log(FINER, "GlassFish dispose failed: " + e.getMessage(), e);
}
}

glassFishInstances.clear();

try {
shutdownInternal();
} catch (GlassFishException ex) {
LOG.log(WARNING, LogFacade.CAUGHT_EXCEPTION, ex.getMessage());
} catch (GlassFishException e) {
LOG.log(WARNING, LogFacade.CAUGHT_EXCEPTION, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public boolean accept(File pathname) {
} else if (pathname.getName().endsWith(JAR_EXT) && !MODULE_EXCLUDES.contains(pathname.getName())) {
try {
moduleJarURLs.add(pathname.toURI().toURL());
} catch (Exception ex) {
LOG.log(Level.WARNING, LogFacade.CAUGHT_EXCEPTION, ex);
} catch (Exception e) {
LOG.log(Level.WARNING, LogFacade.CAUGHT_EXCEPTION, e);
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2024, 2025 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Set;

import org.glassfish.embeddable.GlassFishException;
import org.glassfish.grizzly.config.dom.NetworkListener;
import org.glassfish.grizzly.config.dom.Protocol;

Expand All @@ -38,11 +37,12 @@ public class InfoPrinter {
static final String TITLE = "GLASSFISH STARTED";
static final int TITLE_LENGTH = TITLE.length();

public String getInfoAfterStartup(List<Application> applications, List<NetworkListener> networkListeners) throws GlassFishException {
public String getInfoAfterStartup(List<Application> applications, List<NetworkListener> networkListeners) {

final List<String> listenerUrls = getListenerUrls(networkListeners);
final StringBuilder output = new StringBuilder();
List<Integer[]> linesInfo = new ArrayList<>(); // tuples of index of last line character and line length
// tuples of index of last line character and line length
final List<Integer[]> linesInfo = new ArrayList<>();

final int maxLength = processApplications(applications, listenerUrls, output, linesInfo);

Expand All @@ -54,21 +54,21 @@ public String getInfoAfterStartup(List<Application> applications, List<NetworkLi
}

private void addBorder(final int maxLength, final StringBuilder output) {
output.insert(0, "\n");
output.insert(0, '\n');
output.insert(0, BORDER_CHARACTER);
output.insert(0, " ".repeat(maxLength - 2));
output.insert(0, BORDER_CHARACTER);
output.insert(0, "\n");
output.insert(0, '\n');
final int numberOfBorderCharsInFirstLine = maxLength - 2 - TITLE_LENGTH;
output.insert(0, BORDER_CHARACTER.repeat(numberOfBorderCharsInFirstLine / 2));
output.insert(0, " ");
output.insert(0, ' ');
output.insert(0, TITLE);
output.insert(0, " ");
output.insert(0, ' ');
output.insert(0, BORDER_CHARACTER.repeat(numberOfBorderCharsInFirstLine / 2 + numberOfBorderCharsInFirstLine % 2));
output.append(BORDER_CHARACTER);
output.append(" ".repeat(maxLength - 2));
output.append(BORDER_CHARACTER);
output.append("\n");
output.append('\n');
output.append(BORDER_CHARACTER.repeat(maxLength));
}

Expand Down Expand Up @@ -97,46 +97,43 @@ private int processApplications(List<Application> applications, final List<Strin
int maxLength = 0;
if (applications.isEmpty()) {
final int lengthBefore = output.length();
output.append(BORDER_CHARACTER)
.append(" ")
.append("No applications deployed. Listening on ")
.append(String.join(", ", listenerUrls))
.append(" ")
.append(BORDER_CHARACTER);
output.append(BORDER_CHARACTER).append(' ').append("No applications deployed.");
if (!listenerUrls.isEmpty()) {
output.append(" Listening on " + String.join(", ", listenerUrls));
}
output.append(' ').append(BORDER_CHARACTER);
int lengthAfter = output.length();
output.append("\n");
output.append('\n');
return lengthAfter - lengthBefore;
}
for (Application app : applications) {
final String appUrls = listenerUrls.stream()
.map(url -> {
final String contextRoot = app.getContextRoot();
if (Set.of("", "/").contains(contextRoot)) {
return url;
} else if (contextRoot.startsWith("/")) {
return url + contextRoot;
} else {
return url + "/" + contextRoot;
}
})
.collect(joining(", "));
final String appUrls = listenerUrls.stream().map(url -> {
final String contextRoot = app.getContextRoot();
if (Set.of("", "/").contains(contextRoot)) {
return url;
} else if (contextRoot.startsWith("/")) {
return url + contextRoot;
} else {
return url + "/" + contextRoot;
}
}).collect(joining(", "));

final int lengthBefore = output.length();
output.append(BORDER_CHARACTER)
.append(" ")
.append(app.getName())
.append(" deployed at ")
.append(appUrls)
.append(" ")
.append(BORDER_CHARACTER);
output.append(BORDER_CHARACTER).append(' ').append(app.getName()).append(" deployed");
if (!appUrls.isEmpty()) {
output.append(" at: " + appUrls);
}
output.append(' ').append(BORDER_CHARACTER);

int lengthAfter = output.length();
int lineLength = lengthAfter - lengthBefore;
if (lineLength < TITLE_LENGTH) {
output.append(" ".repeat(TITLE_LENGTH - lineLength));
lengthAfter = output.length();
lineLength = lengthAfter - lengthBefore;
}
linesInfo.add(new Integer[]{lengthAfter - 1, lineLength});
output.append("\n");
linesInfo.add(new Integer[] {lengthAfter - 1, lineLength});
output.append('\n');
maxLength = Math.max(maxLength, lineLength);
}
return maxLength;
Expand Down
Loading