Skip to content

Commit

Permalink
[AS7-809] Converted the protocol subsystem to use i18n loggers and me…
Browse files Browse the repository at this point in the history
…ssages.
  • Loading branch information
jamezp authored and n1hility committed Sep 17, 2011
1 parent 5dc0081 commit f98e2d4
Show file tree
Hide file tree
Showing 17 changed files with 744 additions and 149 deletions.
24 changes: 24 additions & 0 deletions protocol/pom.xml
Expand Up @@ -41,6 +41,16 @@
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-generator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
Expand Down Expand Up @@ -77,4 +87,18 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>
-AgeneratedTranslationFilesPath=${project.build.directory}/generated-translation-files
</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>

</project>
Expand Up @@ -23,13 +23,15 @@

import java.io.IOException;

import org.jboss.logging.Logger;
import org.jboss.remoting3.Attachments;
import org.jboss.remoting3.Channel;
import org.jboss.remoting3.CloseHandler;
import org.jboss.remoting3.MessageInputStream;
import org.jboss.remoting3.MessageOutputStream;

import static org.jboss.as.protocol.ProtocolLogger.ROOT_LOGGER;
import static org.jboss.as.protocol.ProtocolMessages.MESSAGES;

/**
* A wrapper around the {@link Channel} that handles repeated receives on the Channel.
* The standard close, shutdownWrites and awaitClosed methods are hacked to work around
Expand All @@ -42,8 +44,6 @@
*/
public abstract class ProtocolChannel implements Channel, Channel.Receiver {

protected final Logger log = Logger.getLogger("org.jboss.as.protocol");

private final String name;
private final Channel channel;
private boolean start;
Expand All @@ -62,7 +62,7 @@ public synchronized void startReceiving() {
if (!start) {
start = true;
} else {
throw new IllegalStateException("Channel and receiver already started");
throw MESSAGES.alreadyStarted();
}

channel.receiveMessage(this);
Expand Down Expand Up @@ -135,18 +135,18 @@ public void close() throws IOException {

@Override
public void handleError(Channel channel, IOException error) {
log.tracef(error, "Handling error, closing channel %s", this);
ROOT_LOGGER.tracef(error, "Handling error, closing channel %s", this);
if (channel != this.channel) {
log.warn("Received error for wrong channel!");
ROOT_LOGGER.receivedWrongChannel();
}
ended(channel);
}

@Override
public void handleEnd(Channel channel) {
log.tracef("Handling end, closing channel %s", this);
ROOT_LOGGER.tracef("Handling end, closing channel %s", this);
if (channel != this.channel) {
log.warn("Received end for wrong channel!");
ROOT_LOGGER.receivedWrongChannel();
}
ended(channel);
}
Expand All @@ -166,7 +166,7 @@ private void ended(Channel channel) {
try {
close();
} catch (IOException e) {
log.warnf("Got error closing channel %s", e.getMessage());
ROOT_LOGGER.errorClosingChannel(e.getMessage());
}
}
}
Expand Up @@ -21,16 +21,15 @@
*/
package org.jboss.as.protocol;

import static org.jboss.as.protocol.ProtocolMessages.MESSAGES;
import static org.xnio.Options.SASL_POLICY_NOANONYMOUS;
import static org.xnio.Options.SASL_POLICY_NOPLAINTEXT;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.Closeable;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.AccessController;
Expand Down Expand Up @@ -86,7 +85,7 @@ private ProtocolChannelClient(final boolean startedEndpoint,

public static <T extends ProtocolChannel> ProtocolChannelClient<T> create(final Configuration<T> configuration) throws IOException, URISyntaxException {
if (configuration == null) {
throw new IllegalArgumentException("Null configuration");
throw MESSAGES.nullVar("configuration");
}
configuration.validate();

Expand All @@ -105,11 +104,11 @@ public static <T extends ProtocolChannel> ProtocolChannelClient<T> create(final

public Connection connect(CallbackHandler handler) throws IOException {
if (connection != null) {
throw new IllegalStateException("Already connected");
throw MESSAGES.alreadyConnected();
}

// TODO - do we need better way to decide this?
OptionMap map = OptionMap.create(SASL_POLICY_NOANONYMOUS, Boolean.FALSE, SASL_POLICY_NOPLAINTEXT, Boolean.FALSE);
OptionMap map = OptionMap.create(SASL_POLICY_NOANONYMOUS, Boolean.FALSE);
IoFuture<Connection> future;
CallbackHandler actualHandler = handler != null ? handler : new AnonymousCallbackHandler();
WrapperCallbackHandler wrapperHandler = new WrapperCallbackHandler(actualHandler);
Expand Down Expand Up @@ -142,7 +141,7 @@ public Connection connect(CallbackHandler handler) throws IOException {

if (cancel == true) {
future.cancel();
throw new ConnectException("Could not connect to remote server at " + connectTimeout + " within " + connectTimeout + "ms");
throw MESSAGES.couldNotConnect(connectTimeout);
}
}

Expand All @@ -152,7 +151,7 @@ public Connection connect(CallbackHandler handler) throws IOException {

public T openChannel(String channelName) throws IOException {
if (connection == null) {
throw new IllegalStateException("Not connected");
throw MESSAGES.notConnected();
}
Channel channel = connection.openChannel(channelName, OptionMap.EMPTY).get();
T wrapped = channelFactory.create(channelName, channel);
Expand Down Expand Up @@ -202,24 +201,24 @@ public Configuration() {

void validate() {
if (endpointName == null && endpoint == null) {
throw new IllegalArgumentException("Null endpoint name and null endpoing");
throw MESSAGES.nullParameters("endpointName", "endpoint");
}
if (optionMap == null) {
throw new IllegalArgumentException("Null option map");
throw MESSAGES.nullVar("optionMap");
}
if (uriScheme == null && endpoint == null) {
throw new IllegalArgumentException("Null uriScheme name");
throw MESSAGES.nullVar("uriScheme");
}
if (uriScheme != null && endpoint != null) {
throw new IllegalArgumentException("Can't set uriScheme with specified endpoint");
throw MESSAGES.cannotSetUriScheme();
}
if (uri == null) {
throw new IllegalArgumentException("Null uri");
throw MESSAGES.nullVar("uri");
}
if (endpoint != null){
//The below does not work so just hard code it for now
if (!uri.getScheme().equals("remote")) {
throw new IllegalArgumentException("Only 'remote' is a valid url");
throw MESSAGES.invalidUrl("remote");
}
/*try {
endpoint.getConnectionProviderInterface(uri.getScheme(), ConnectionProviderFactory.class);
Expand All @@ -228,20 +227,20 @@ void validate() {
}*/
} else {
if (!uriScheme.equals(uri.getScheme())) {
throw new IllegalArgumentException("Scheme " + uriScheme + " does not match uri " + uri);
throw MESSAGES.unmatchedScheme(uriScheme, uri);
}
}
if (endpoint != null && executor != null) {
throw new IllegalArgumentException("Don't need an executor when specified endpoint");
throw MESSAGES.executorUnneeded();
}
if (endpoint == null && executor == null) {
throw new IllegalArgumentException("Need an executor when endpoint is not specified");
throw MESSAGES.executorNeeded();
}
if (channelFactory == null) {
throw new IllegalArgumentException("Null channel factory");
throw MESSAGES.nullVar("channelFactory");
}
if (connectTimeout != -1 && connectTimeoutProperty != null) {
throw new IllegalArgumentException("Can't use both a connect timeout and a connect timeout property");
throw MESSAGES.cannotSpecifyMultipleTimeouts();
}
if (connectTimeoutProperty != null) {
connectTimeout = AccessController.doPrivileged(new PrivilegedAction<Long>() {
Expand Down

0 comments on commit f98e2d4

Please sign in to comment.