Skip to content

Commit

Permalink
add remoting test cocde
Browse files Browse the repository at this point in the history
  • Loading branch information
kylinsoong committed Jul 10, 2014
1 parent 5b9f3c7 commit 0f1f923
Show file tree
Hide file tree
Showing 14 changed files with 754 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jboss.logging;

import org.jboss.as.host.controller.HostControllerLogger;

public class LoggerTest {

public static void main(String[] args) {

System.out.println(HostControllerLogger.class.getPackage().getName());

HostControllerLogger.ROOT_LOGGER.tracef("trying to reconnect to %s current-state (%s) required-state (%s)", "jo004006", "SERVER_STARTED", "SERVER_STARTED");
}

}
22 changes: 22 additions & 0 deletions logging/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.wildfly.logging</groupId>
<artifactId>wildfly-logging</artifactId>
<version>1.0</version>
<name>Parent</name>
<description>Parent of WildFly logging</description>
<packaging>pom</packaging>

<url>https://github.com/kylinsoong</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>quickstart</module>
</modules>

</project>
45 changes: 45 additions & 0 deletions logging/quickstart/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-quickstart</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JBoss logging quickstart</name>
<description>JBoss logging quickstart</description>

<url>https://github.com/kylinsoong</url>

<properties>
<logging.version>3.1.2.GA-redhat-1</logging.version>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
<compiler.plugin.version>2.3.1</compiler.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${logging.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jboss.logging.sample;

import org.jboss.logging.Logger;

public class HelloWorld {

private static final Logger LOGGER = Logger.getLogger(HelloWorld.class);

public static void main(String[] args) {

LOGGER.trace("TRACE Message");
LOGGER.debug("DEBUG Message");
LOGGER.info("INFO Message");
LOGGER.error("Error Message");
LOGGER.fatal("FATAL Message");

LOGGER.error("Configuration file not found.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jboss.logging.sample;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.jboss.logging.Logger;

public class LocalSystemConfig {

private static final Logger LOGGER = Logger.getLogger(LocalSystemConfig.class);

public Properties openCustomProperties(String configname)throws FileNotFoundException {
Properties props = new Properties();
try {
LOGGER.info("Loading custom configuration from " + configname);
props.load(new FileInputStream(configname));
} catch (IOException e) {
LOGGER.error("Custom configuration file (" + configname + ") not found. Using defaults.");
throw new FileNotFoundException(configname);
}

return props;
}

public static void main(String[] args) throws FileNotFoundException {

new LocalSystemConfig().openCustomProperties("XXOO");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jboss.logging.sample;

import org.jboss.logging.Logger;

public class LoggerTest {

public static void main(String[] args) {

System.setProperty("org.jboss.logging.provider", "jboss");

Logger logger = Logger.getLogger(LoggerTest.class, "com.kylin.test");

logger.info("logger test");
}

}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<module>undertow</module>
<module>perf</module>
<module>domain</module>
<module>remoting</module>
<module>logging</module>
</modules>

</project>
22 changes: 22 additions & 0 deletions remoting/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.wildfly.remoting</groupId>
<artifactId>wildfly-remoting</artifactId>
<version>1.0</version>
<name>Parent</name>
<description>Parent of WildFly remoting</description>
<packaging>pom</packaging>

<url>https://github.com/kylinsoong</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>quickstart</module>
</modules>

</project>
64 changes: 64 additions & 0 deletions remoting/quickstart/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jboss.remoting3</groupId>
<artifactId>jboss-remoting-quickstart</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JBoss Remoting 3 quickstart</name>
<description>JBoss Remoting 3 quickstart</description>

<url>https://github.com/kylinsoong</url>

<properties>
<xnio.version>3.0.7.GA-redhat-1</xnio.version>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
<compiler.plugin.version>2.3.1</compiler.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.jboss.remoting3</groupId>
<artifactId>jboss-remoting</artifactId>
<version>3.2.16.GA-redhat-1</version>
</dependency>
<!-- -->
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<version>${xnio.version}</version>
</dependency>
</dependencies>

<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.jboss.remoting3.test.Runner</mainClass>
</manifest>
<manifestEntries>
<Jar-Version>${project.version}</Jar-Version>
<Jar-Name>${project.artifactId}</Jar-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.jboss.remoting3.sample;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.jboss.remoting3.Channel;
import org.jboss.remoting3.Endpoint;
import org.jboss.remoting3.MessageInputStream;
import org.jboss.remoting3.OpenListener;
import org.jboss.remoting3.Remoting;
import org.jboss.remoting3.remote.RemoteConnectionProviderFactory;
import org.jboss.remoting3.security.SimpleServerAuthenticationProvider;
import org.jboss.remoting3.spi.NetworkServerProvider;
import org.xnio.IoUtils;
import org.xnio.OptionMap;
import org.xnio.Options;
import org.xnio.Sequence;
import org.xnio.channels.AcceptingChannel;
import org.xnio.channels.ConnectedStreamChannel;

public class CharSequenceReceiver {

private static final int THREAD_POOL_SIZE = 100;
private static final int BUFFER_SIZE = 8192;
private static byte[] buffer;

protected final Endpoint serverEndpoint;

private AcceptingChannel<? extends ConnectedStreamChannel> server;

public CharSequenceReceiver() throws IOException {
serverEndpoint = Remoting.createEndpoint("connection-test-server", OptionMap.create(Options.WORKER_TASK_CORE_THREADS, THREAD_POOL_SIZE, Options.WORKER_TASK_MAX_THREADS, THREAD_POOL_SIZE));
serverEndpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
final NetworkServerProvider networkServerProvider = serverEndpoint.getConnectionProviderInterface("remote", NetworkServerProvider.class);
SimpleServerAuthenticationProvider provider = new SimpleServerAuthenticationProvider();
provider.addUser("bob", "test", "pass".toCharArray());
server = networkServerProvider.createServer(new InetSocketAddress("localhost", 30123), OptionMap.create(Options.SASL_MECHANISMS, Sequence.of("CRAM-MD5")), provider, null);
System.out.println("Server Created, " + server.getLocalAddress());

serverEndpoint.registerService("test", new OpenListener(){

public void channelOpened(Channel channel) {
channel.receiveMessage(new Channel.Receiver(){

public void handleError(Channel channel, IOException error) {

}

public void handleEnd(Channel channel) {
// System.out.println(channel.getConnection().getRemoteEndpointName() + " ended");
}

public void handleMessage(Channel channel, MessageInputStream message) {
try {
channel.receiveMessage(this);
buffer = new byte[BUFFER_SIZE];
while (message.read(buffer) > -1);
System.out.println(" Receive: " + new String(buffer));
} catch (Exception e) {
e.printStackTrace();
} finally {
IoUtils.safeClose(message);
}
}
});
}

public void registrationTerminated() {

}}, OptionMap.EMPTY);
}


public static void main(String[] args) throws IOException {
new CharSequenceReceiver();
}

}
Loading

0 comments on commit 0f1f923

Please sign in to comment.