Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-17280936: Use SLF4J API instead of JUL #71

Merged
merged 11 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 2 additions & 1 deletion extras/bundles/grizzly-httpservice-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
<configuration>
<classifier>sources</classifier>
<excludeScope>provided</excludeScope>
<excludeArtifactIds>junit</excludeArtifactIds>
<excludeGroupIds>org.apache.logging.log4j</excludeGroupIds>
<excludeArtifactIds>junit,slf4j-api</excludeArtifactIds>
<!-- fudge an actual source hierarchy so that the source
plugin can actually do something useful. Otherwise,
you'll end up with an empty source jar -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;



import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.Connection;
Expand All @@ -57,6 +57,8 @@
import org.glassfish.grizzly.utils.DelayedExecutor;
import org.glassfish.grizzly.utils.DelayedExecutor.DelayQueue;
import org.glassfish.grizzly.utils.Futures;
import org.slf4j.Logger;

import static org.glassfish.grizzly.connectionpool.SingleEndpointPool.*;

/**
Expand Down Expand Up @@ -628,18 +630,14 @@ public Connection poll(final Endpoint<E> endpoint) throws IOException {
public boolean release(final Connection connection) {
final ConnectionInfo<E> info = connectionToSubPoolMap.get(connection);
if (info != null) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Returning {0} to endpoint pool {1}",
new Object[] {connection, info.endpointPool});
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Returning {} to endpoint pool {}", connection, info.endpointPool);
}
// optimize release() call to avoid redundant map lookup
return info.endpointPool.release0(info);
} else {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"No ConnectionInfo available for {0}. Closing connection.",
connection);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No ConnectionInfo available for {}. Closing connection.", connection);
}
connection.closeSilently();
return false;
Expand All @@ -665,10 +663,8 @@ public boolean attach(final Endpoint<E> endpoint,
throws IOException {

final SingleEndpointPool<E> sePool = obtainSingleEndpointPool(endpoint);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Associating foreign connection with pool {0} using endpoint key {1}.",
new Object[] {sePool, endpoint});
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Associating foreign connection with pool {} using endpoint key {}.", sePool, endpoint);
}
return sePool.attach(connection);
}
Expand All @@ -688,10 +684,8 @@ public boolean attach(final Endpoint<E> endpoint,
*/
public boolean detach(final Connection connection) {
final ConnectionInfo<E> info = connectionToSubPoolMap.get(connection);
if (info != null && LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Detaching {0} from endpoint pool {1}.",
new Object[] { connection, info.endpointPool});
if (info != null && LOGGER.isDebugEnabled()) {
LOGGER.debug("Detaching {} from endpoint pool {}.", connection, info.endpointPool);
}
return info != null && info.endpointPool.detach(connection);
}
Expand All @@ -708,10 +702,8 @@ public boolean detach(final Connection connection) {
public void close(final Endpoint<E> endpoint) {
final SingleEndpointPool<E> sePool = endpointToPoolMap.remove(endpoint);
if (sePool != null) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Closing pool associated with endpoint key {0}",
endpoint);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Closing pool associated with endpoint key {}", endpoint);
}
sePool.close();
}
Expand All @@ -729,8 +721,8 @@ public void close() {
if (isClosed) {
return;
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Shutting down. Closing all pools; shutting down executors as needed.");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Shutting down. Closing all pools; shutting down executors as needed.");
}
isClosed = true;

Expand Down Expand Up @@ -782,17 +774,13 @@ protected SingleEndpointPool<E> obtainSingleEndpointPool(

sePool = endpointToPoolMap.get(endpoint);
if (sePool == null) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Creating new endpoint pool for key {0}",
endpoint);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Creating new endpoint pool for key {}", endpoint);
}
sePool = createSingleEndpointPool(endpoint);
endpointToPoolMap.put(endpoint, sePool);
} else if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Returning existing pool {0} for key {1}",
new Object[]{sePool, endpoint});
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Returning existing pool {} for key {}", sePool, endpoint);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.grizzly.CloseListener;
import org.glassfish.grizzly.CloseType;
import org.glassfish.grizzly.CompletionHandler;
Expand All @@ -70,6 +69,7 @@
import org.glassfish.grizzly.utils.DelayedExecutor;
import org.glassfish.grizzly.utils.DelayedExecutor.DelayQueue;
import org.glassfish.grizzly.utils.Futures;
import org.slf4j.Logger;

/**
* The single endpoint {@link Connection} pool implementation, in other words
Expand Down Expand Up @@ -1252,8 +1252,8 @@ private final class ConnectCompletionHandler

@Override
public void completed(final Connection connection) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Pool connection is established {0}", connection);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Pool connection is established {}", connection);
}

boolean isOk = false;
Expand Down Expand Up @@ -1307,8 +1307,8 @@ private void onFailedToConnect(final Throwable t) {
// check if there is still a thread(s) waiting for a connection
// and reconnect mechanism is enabled
if (reconnectQueue != null && !asyncWaitingList.isEmpty()) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Pool connect operation failed, schedule reconnect");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Pool connect operation failed, schedule reconnect");
}
if (++failedConnectAttempts > maxReconnectAttempts) {
notifyAsyncPollers = true;
Expand Down Expand Up @@ -1359,8 +1359,8 @@ protected static final class ConnectTimeoutWorker

@Override
public boolean doWork(final ConnectTimeoutTask connectTimeoutTask) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Pool connect timed out");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Pool connect timed out");
}
connectTimeoutTask.connectFuture.cancel(false);
return true;
Expand Down Expand Up @@ -1504,9 +1504,8 @@ public boolean doWork(final Link<AsyncPoll> asyncPollLink) {
}

if (removed) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Async poll timed out for {0}",
asyncPollLink.getValue());
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Async poll timed out for {}", asyncPollLink.getValue());
}

final AsyncPoll asyncPoll = asyncPollLink.getValue();
Expand Down Expand Up @@ -1563,9 +1562,8 @@ protected static final class ConnectionTTLWorker

@Override
public boolean doWork(final ConnectionInfo ci) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Connection {0} TTL expired",
ci.connection);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Connection {} TTL expired", ci.connection);
}

synchronized(ci.endpointPool.poolSync) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;


import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
Expand All @@ -71,6 +71,7 @@
import org.glassfish.grizzly.http.server.HttpHandler;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;
import org.slf4j.Logger;
import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -201,7 +202,7 @@ public long getAsyncTimeout(final TimeUnit timeUnit) {
*/
@Override
public void service(Request req, Response res) throws Exception {
LOGGER.log(Level.FINE, "Received a request. The request thread {0} .", Thread.currentThread());
LOGGER.debug("Received a request. The request thread {} .", Thread.currentThread());
// TODO: synchornous execution for ?wsdl, non AsyncProvider requests
final WSHTTPConnection connection = new JaxwsConnection(httpAdapter,
req, res, req.isSecure(), isAsync);
Expand Down Expand Up @@ -231,7 +232,7 @@ public void cancelled() {
httpAdapter.handle(connection);
}

LOGGER.log(Level.FINE, "Getting out of service(). Done with the request thread {0} .", Thread.currentThread());
LOGGER.debug("Getting out of service(). Done with the request thread {} .", Thread.currentThread());
}

/**
Expand Down Expand Up @@ -307,4 +308,4 @@ private List<SDDocumentSource> buildDocList() {

return r;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;


import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.io.NIOInputStream;
import org.slf4j.Logger;

/**
* Entry point for the multipart message processing.
Expand Down Expand Up @@ -130,7 +131,7 @@ public static void scan(final Request request,
if (completionHandler != null) {
completionHandler.failed(e);
} else {
LOGGER.log(Level.WARNING, "Error occurred, but no CompletionHandler installed to handle it", e);
LOGGER.warn("Error occurred, but no CompletionHandler installed to handle it", e);
}
}
}
Expand Down Expand Up @@ -193,7 +194,7 @@ public static void scan(final MultipartEntry multipartMixedEntry,
if (completionHandler != null) {
completionHandler.failed(e);
} else {
LOGGER.log(Level.WARNING, "Error occurred, but no CompletionHandler installed to handle it", e);
LOGGER.warn("Error occurred, but no CompletionHandler installed to handle it", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,40 @@
package org.glassfish.grizzly.servlet.extras;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.EmptyCompletionHandler;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.ReadHandler;
import org.glassfish.grizzly.http.io.NIOInputStream;
import org.glassfish.grizzly.http.io.NIOReader;
import org.glassfish.grizzly.http.multipart.ContentDisposition;
import org.glassfish.grizzly.http.multipart.MultipartEntry;
import org.glassfish.grizzly.http.multipart.MultipartEntryHandler;
import org.glassfish.grizzly.http.multipart.MultipartScanner;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;
import org.glassfish.grizzly.http.io.NIOInputStream;
import org.glassfish.grizzly.http.io.NIOReader;
import org.glassfish.grizzly.http.util.Parameters;
import org.glassfish.grizzly.memory.ByteBufferArray;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.grizzly.servlet.HttpServletRequestImpl;
import org.glassfish.grizzly.servlet.HttpServletResponseImpl;
import org.slf4j.Logger;

/**
* <p>
Expand Down Expand Up @@ -165,7 +165,7 @@ public void completed(final Request request) {
try {
filterChain.doFilter(servletRequest, servletResponse);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
LOGGER.error(e.toString(), e);
} finally {
if (deleteAfterRequestEnd) {
clean(dir);
Expand All @@ -177,7 +177,7 @@ public void completed(final Request request) {
@Override
public void failed(Throwable throwable) {
// if failed - log the error
LOGGER.log(Level.SEVERE, "Upload failed.", throwable);
LOGGER.error("Upload failed.", throwable);
// Complete the asynchronous HTTP request processing.
response.resume();
}
Expand Down Expand Up @@ -219,9 +219,8 @@ private static void clean(final File file) {
File[] f = file.listFiles();
if (f.length == 0) {
if (!file.delete()) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(String.format("Unable to delete directory %s. Will attempt deletion again upon JVM exit.",
file.getAbsolutePath()));
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Unable to delete directory {}. Will attempt deletion again upon JVM exit.", file.getAbsolutePath());
}
}
} else {
Expand All @@ -231,9 +230,8 @@ private static void clean(final File file) {
}
} else {
if (!file.delete()) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(String.format("Unable to delete file %s. Will attempt deletion again upon JVM exit.",
file.getAbsolutePath()));
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Unable to delete file {}. Will attempt deletion again upon JVM exit.", file.getAbsolutePath());
}
file.deleteOnExit();
}
Expand Down Expand Up @@ -285,8 +283,7 @@ public void handle(final MultipartEntry multipartEntry) throws Exception {
// Get the NIOInputStream to read the multipart entry content
final NIOInputStream inputStream = multipartEntry.getNIOInputStream();

LOGGER.log(Level.FINE, "Uploading file {0}",
new Object[]{filename});
LOGGER.debug("Uploading file {}", filename);

// start asynchronous non-blocking content read.
inputStream.notifyAvailable(
Expand Down Expand Up @@ -394,7 +391,7 @@ public void onAllDataRead() throws Exception {
*/
@Override
public void onError(Throwable t) {
LOGGER.log(Level.WARNING, String.format("Upload of file %s failed.", filename), t);
LOGGER.warn("Upload of file {} failed.", filename, t);
// finish the upload
finish();
}
Expand Down
Loading