you can not redoflnd channe的中文字

How to create a simple EJB3 project in Eclipse (JBoss 7.1) >> the Open Tutorials
Sign In | Register the Open TutorialsExamplesJava EEEJB3How to create a simple EJB3 project in Eclipse (JBoss 7.1) 7 February 2012 By Nithya Vasudevan 131,656 views <span
class="dsq-postid" rel="1085 /?p= Comments
56 Flares &#215; Contents1 Environment Used2 Project Description:3 Creating New EJB Project4 Creating Session Bean and Bean Interface5 Coding Bean and the Interface6 Deploying EJB project7 Start/Restart the Server8 Creating Client8.1 Creating JNDI InitialContext8.2 Creating client class8.3 Setting up EJB client context properties8.4 Adding JAR files required for the client to run the client application8.5 Run the clientEnvironment UsedJDK 6 (Java SE 6)EJB 3.0 (stateless session bean)Eclipse Indigo IDE for Java EE Developers (3.7.1)JBoss Tools – Core 3.3.0 M5 for Eclipse Indigo (3.7.1)JBoss Application Server (AS) 7.1.0.CR1b / FinalSetting up development environment: Read this page for installing and setting up the environment for developing and deploying EJB 3.0 Session bean on JBoss application server.Project Description:We are going to create a simple EJB 3 HelloWorld stateless session bean project and a remote Java application client which will call/invoke the bean.This &#8220;HelloWorld&#8221; example explains how to develop, deploy and run EJB3 Session Bean (stateless and stateful) in JBoss application server.For testing this &#8220;HelloWorld&#8221; example we write a remote Java Application Client (main() method).For simplicity, the session bean and the client to access the session bean are created in the same project.Creating New EJB ProjectOpen Eclipse IDE and create a new EJB project which can be done in three ways,Right click on Project Explorer -> New -> EJB ProjectFile menu -> New -> EJB ProjectClick on the down arrow on New icon on toolbar -> EJB ProjectEnter the project name as &#8220;HelloWorldSessionBean&#8221; and make sure the JBoss 7.1 Runtime has been selected with the EJB 3.0 Module version.Click Next -> Next -> and Finish.You will see an EJB project in the Project Explorer view.Creating Session Bean and Bean InterfaceRight click on ejbModule -> New -> Session Bean (EJB 3.x)Enter the Java package name as com.ibytecode.businesslogicEnter the Class name as HelloWorldBeanSelect the State type as StatelessCheck the Remote Business Interface and enter the name as com.ibytecode.business.HelloWorld. The business interface will be created in different package (com.ibytecode.business)Click FinishCoding Bean and the InterfaceOpen Bean Interface and type the following code and save the file (Ctrl+s).Interface can be either @Remote or @Local. In this example we have used @Remote.
package com.ibytecode.
import javax.ejb.R
public interface HelloWorld {
public String sayHello();
Open Bean and type the following code and save the file.Bean type can either be @Stateful or @Stateless. In this example we have used @Stateless.
package com.ibytecode.
import com.ibytecode.business.HelloW
import javax.ejb.S
@Stateless
public class HelloWorldBean implements HelloWorld {
public HelloWorldBean() {
public String sayHello() {
return &Hello World !!!&;
Now the Stateless Session Bean has been created. The next step is to deploy the bean on the server.Deploying EJB projectNow we need to deploy the stateless session bean “HelloWorldBean” on server.Deploying the project can be done in two ways,Right click on the EJB project -> Run As -> Run On Server. Select the existing “JBoss 7.1 Runtime Server” and click Finish.Right click on “JBoss 7.1 Runtime Server” available in Servers view -> Add and Remove… -> Select the EJB JAR file from the left pane and click Add-> and then Finish.Start/Restart the ServerRight click on “JBoss 7.1 Runtime Server” from Servers view and click on Start if it has not yet been started. If the project is deployed properly with global JNDI mapping then you will see the following message in the console.Creating ClientThe next step is to write a remote Java client application (with main())
for accessing and invoking the EJBs deployed on the server Client uses JNDI to lookup for a proxy of your bean and invokes method on that proxy.Creating JNDI InitialContextObtaining a Context using InitialContextAll naming service operations are performed on some implementation of the javax.naming.Context interface. Therefore, the starting point of interacting with the naming service is to obtain a Context by providing the properties specific to the server implementation being used. In our case it is, JBoss Application Server.To create a javax.naming.InitialContext, we need to initialize it with properties from the environment. JNDI verifies each property&#8217;s value by merging the values from the following two sources,Using parameterized constructor of InitialContext which takes properties of supplied environmentjndi.properties resource files found on the classpath.NOTE:We will use parameterized constructor for initializing the InitialContext.For JBoss AS 7 we need to set the Context.URL_PKG_PREFIXES property with value &#8220;org.jboss.ejb.client.naming&#8221; to obtain the InitialContext.The following utility class is used to create InitialContext for JBoss AS and can be reused in all applications. Otherwise the code written in this class should be repeated in all clients.Right click on ejbModule -> New -> ClassEnter the package name as com.ibytecode.clientutilityEnter the Class name as ClientUtilityClick on Finish
package com.ibytecode.
import java.util.P
import javax.naming.C
import javax.naming.InitialC
import javax.naming.NamingE
public class ClientUtility {
private static Context initialC
private static final String PKG_INTERFACES = &org.jboss.ejb.client.naming&;
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
initialContext = new InitialContext(properties);
return initialC
Creating client classRight click on ejbModule -> New -> ClassEnter the package name as com.ibytecode.clientEnter the Class name as EJBApplicationClientCheck the main() method optionClick on Finish
package com.ibytecode.
import javax.naming.C
import javax.naming.NamingE
import com.ibytecode.business.HelloW
import com.ibytecode.businesslogic.HelloWorldB
import com.ibytecode.clientutility.ClientU
public class EJBApplicationClient {
public static void main(String[] args) {
HelloWorld bean = doLookup();
System.out.println(bean.sayHello()); // 4. Call business logic
private static HelloWorld doLookup() {
Context context =
HelloWorld bean =
// 1. Obtaining Context
context = ClientUtility.getInitialContext();
// 2. Generate JNDI Lookup name
String lookupName = getLookupName();
// 3. Lookup and cast
bean = (HelloWorld) context.lookup(lookupName);
} catch (NamingException e) {
e.printStackTrace();
private static String getLookupName() {
The app name is the EAR name of the deployed EJB without .ear suffix.
Since we haven't deployed the application as a .ear,
the app name for us will be an empty string
String appName = &&;
/* The module name is the JAR name of the deployed EJB
without the .jar suffix.
String moduleName = &HelloWorldSessionBean&;
/*AS7 allows each deployment to have an (optional) distinct name.
This can be an empty string if distinct name is not specified.
String distinctName = &&;
// The EJB bean implementation class name
String beanName = HelloWorldBean.class.getSimpleName();
// Fully qualified remote interface name
final String interfaceName = HelloWorld.class.getName();
// Create a look up string name
String name = &ejb:& + appName + &/& + moduleName + &/& +
distinctName
+ &/& + beanName + &!& + interfaceN
Setting up EJB client context propertiesAn EJB client context is a context which contains contextual information for carrying out remote invocations on EJBs. This is a JBoss AS specific API. The EJB client context can be associated with multiple EJB receivers. Each EJB receiver is capable of handling invocations on different EJBs. For example, an EJB receiver &#8220;ClientA&#8221; might be able to handle invocation on a bean identified by app-A/module-A/distinctinctName-A/BeanA!com.ibc.RemoteBeanA, app-B/module-B/distinctName-B/BeanB!RemoteBeanB, etc. Each such EJB receiver knows about what set of EJBs it can handle and each of the EJB receiver knows which server target to use for handling the invocations on the bean. The server IP address and its remoting port should be specified in the properties file placed in the client classpath. This properties file (EJB client context) will then be used internally by the JNDI implementation to handle invocations on the bean proxy.Create a file &#8220;jboss-ejb-client.properties&#8221; in the classpath of the application. We can place it in ejbModule folder of our application. The jboss-ejb-client.properties contains the following properties:remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=falseremote.connections=defaultremote.connection.default.host=localhost remote.connection.default.port = 4447 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=falseAdding JAR files required for the client to run the client applicationOpen Run Configurations… in Run menu or Run Configurations in Run iconSelect the client application (EJBApplicationClient) under Java Application from left pane and open the Classpath tab from right side pane. If you don&#8217;t see your client application, run it once. Select &#8220;User Entries&#8221; and click on &#8220;Add External JARs&#8221;Add the following JAR files.JAR nameLocationjboss-transaction-api_1.1_spec-1.0.0.Final.jarAS7_HOME/modules/javax/transaction/api/main/jboss-ejb-api_3.1_spec-1.0.1.Final.jarAS7_HOME/modules/javax/ejb/api/main/jboss-ejb-client-1.0.0.Beta10.jarAS7_HOME/modules/org/jboss/ejb-client/main/jboss-marshalling-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/main/xnio-api-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/main/jboss-remoting-3.2.0.CR6.jarAS7_HOME/modules/org/jboss/remoting3/main/jboss-logging-3.1.0.Beta3.jarAS7_HOME/modules/org/jboss/logging/main/xnio-nio-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/nio/main/jboss-sasl-1.0.0.Beta9.jarAS7_HOME/modules/org/jboss/sasl/main/jboss-marshalling-river-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/river/main/You can also add it in Build path (Right click on your EJB Project->Properties, select Java Build Path from left side pane and select Libraries from right side and click on Add External JARs)If you are using JBoss Application Server (AS) 7.1.0 Final version then it is sufficient to add only one client JAR file (jboss-client-7.1.0.Final.jar) which is located in AS7_HOME/bin/clientThe figure below shows the final directory structure of this example. Run the clientUse Ctrl + F11 to run the client. Hello World !!!Related posts:How to setup EJB3 development environment (Eclipse, JBoss 5.1) EJB3 Introduction Installing JBoss Tools in Eclipse Tags: ejb3, ejb3 stateless session bean, jboss as, jboss in eclipse ide, jndi lookup clientNextNo ejb client jar file in classpathIncorrect Lookup nameClient properties file not in classpathSo go through those issues and try again.Pingback: JavaPinsPingback: How To Develop Android Apps In Eclipse | X Power Ionizer PostPingback: Fix Jboss Web 3.0.0 Cr2 Error Report Windows XP, Vista, 7, 8 [Solved]Follow @opentutorialsPopular PostsHow to create a Servlet with Eclipse and Tomcat Pagination in Servlet and JSP Android: Custom ListView with Image and Text using ArrayAdapter How to create a simple EJB3 project in Eclipse (JBoss 7.1) Android: Expandable List View Example How to create and consume a simple Web Service using JAX WS Generate Java class from XML Schema using JAXB &#039;xjc&#039; command How to configure Apache Tomcat in Eclipse IDE? How to create a simple Restful Web Service using Jersey JAX RS API How to create EJB3 JPA Project in Eclipse (JBoss AS 7.1) Recent CommentsBACK TO TOP &This site in other countries/regions:Stack Overflow is a question and answer site for professional and enthusiast programmers. It&#39;s 100% free, no registration required.
I decided to find out how many msg/sec my notebook can prosess from multiple clients.
I've changed Echo client/server from examples in next easy way:
1) on the client side I have infinite loop in the channelActive() method. Loop sends messages.
2) on the server side I have channelRead() method that handles incoming messages
When I run my client 2 times (in 2 separet threads), I expect to see how server processes the clients in 2 threads.
Instead, the server processes only 1 client connnection, sometimes none at all.
I looked at my client threads and find out they can't exit from the while loop in ChannelOutboundBuffer.addFlush() method.
I can't understand what I've made wrong. I use netty 4.0.21
EchoClient.java
public static void main(String[] args) throws Exception {
// Configure the client.
final EventLoopGroup group = new NioEventLoopGroup();
Runnable r = new Runnable() {
public void run() {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.handler(new ChannelInitializer&SocketChannel&() {
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new EchoClientHandler());
// Start the client.
ChannelFuture f = b.connect(HOST, PORT).sync();
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Shut down the event loop to terminate all threads.
group.shutdownGracefully();
for (int i = 0; i & 2; i++) {
Thread t = new Thread(r, i + " lalala");
t.start();
EchoClientHandler.java
public class EchoClientHandler extends ChannelInboundHandlerAdapter {
public void channelActive(ChannelHandlerContext ctx) {
while (true) {
ByteBuf time = ctx.alloc().buffer(4);
time.writeInt(number);
ctx.writeAndFlush(time);
ctx.flush();
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
ctx.fireChannelReadComplete();
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
cause.printStackTrace();
ctx.close();
ctx.fireExceptionCaught(cause);
EchoServer.java
public final class EchoServer {
public static void main(String[] args) throws Exception {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new ))
.childHandler(new ChannelInitializer&SocketChannel&() {
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new EchoServerHandler());
// Start the server.
ChannelFuture f = b.bind(8007).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
EchoServerHandler.java
public class EchoServerHandler extends ChannelInboundHandlerAdapter {
long max_msg = 10000;
long cur_msg = 0;
long startTime = System.nanoTime();
final int NANOS_IN_SEC = ;
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ReferenceCountUtil.release(msg);
if (cur_msg == max_msg) {
System.out.println("Throughput (msg/sec) : " + max_msg * NANOS_IN_SEC / (System.nanoTime() - startTime));
cur_msg = 0;
startTime = System.nanoTime();
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
ctx.fireChannelReadComplete();
You can not have an infinite loop in your channelActive(...) method as this will block the EventLoop which is used for multiple connections. This way you will basically block all processing of events for all Channels that use this EventLoop.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledThis site in other countries/regions:Stack Overflow is a question and answer site for professional and enthusiast programmers. It&#39;s 100% free, no registration required.
I am trying to run users_test.rb file which just has
test "the truth" do
assert true
I do have a likes table, still I am getting this error. Why so?
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
channelappnew
rake db:test:clone
channelappnew
rake db:test:clone_structure
channelappnew
rake db:migrate
channelappnew
rake db:test:load
channelappnew
rake db:test:prepare
channelappnew
rake db:test:purge
channelappnew
ruby -Itest test/unit/user_test.rb
Loaded suite test/unit/user_test
test_the_truth(UserTest):
ActiveRecord::StatementInvalid: Could not find table 'likes'
Finished in 0.058371 seconds.
1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
17.13 tests/s, 0.00 assertions/s
1,222133368
before test do rake db:test:prepare
Have you run rake db:migrate?
Check database if the table exists. If you are working with sqlite, then call sqlite3 db/development.sqlite3 and then issue command .schema
You can manually delete database db/test.sqlite3 and then re-create it with rake db:setup.
Have you checked your fixtures? It has happened to me that I modified a migration but the fixture staid the same, therefore causing a error.
11.3k1559107
Sometimes it is caused due to multiple versions of active record gems. Please uninstall all gems except one that your application is using. I faced the same problem and did same what i said. It worked.
I just had the same problem and found the solution in db/schema.rb:
# Could not dump table "xxx" because of following StandardError
Unknown type 'bool' for column 'yyy'
maybe this helps!
"bool" worked everywhere except for this schema.rb, but the migrations where executed correctly in development mode.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 you can not advance 的文章

 

随机推荐