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

更新dubbo编译的jdk版本,提供一个非spring集成方式的dubbo样例(方便阅读源代码) #147

Closed
wants to merge 4 commits into from
Closed
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

605 changes: 605 additions & 0 deletions dubbo-test/dubbo-test-examples/201512041331000400_3940.threadDump

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.threadpool.support;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.examples.nospring.JStack;

/**
* Abort Policy.
* Log warn info when abort.
*
* @author ding.lid
*/
public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy {

protected static final Logger logger = LoggerFactory.getLogger(AbortPolicyWithReport.class);

private final String threadName;

private final URL url;

private long lastDumpTime = 0;

public AbortPolicyWithReport(String threadName, URL url) {
this.threadName = threadName;
this.url = url;
}

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
String msg = String.format("Thread pool is EXHAUSTED!" +
" Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," +
" Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!" ,
threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(),
e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(),
url.getProtocol(), url.getIp(), url.getPort());
long now = System.currentTimeMillis();
if(now - lastDumpTime > 1000*60*5){
lastDumpTime = now;
JStack jstackCmd = new JStack(ConfigUtils.getPid(), "d:\\", "-l");
jstackCmd.exec();
logger.info("Thread Dump stored in " + jstackCmd.getDumpFile());
}
logger.warn(msg);
throw new RejectedExecutionException(msg);
}

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.examples.callback;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.examples.callback.api.CallbackListener;
import com.alibaba.dubbo.examples.callback.api.CallbackService;
/**
* CallbackConsumer
*
* @author william.liangf
*/
public class CallbackConsumer {
public static void main(String[] args) throws Exception {
String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
CallbackService callbackService = (CallbackService) context.getBean("callbackService");
callbackService.addListener("foo.bar", new CallbackListener() {
public void changed(String msg) {
System.out.println("callback1:" + msg);
}
});
System.in.read();
}
}
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.examples.callback;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.examples.callback.api.CallbackListener;
import com.alibaba.dubbo.examples.callback.api.CallbackService;

/**
* CallbackConsumer
*
* @author william.liangf
*/
public class CallbackConsumer {

public static void main(String[] args) throws Exception {
String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
final CallbackService callbackService = (CallbackService) context.getBean("callbackService");
callbackService.addListener("foo.bar", new CallbackListener() {
public void changed(String msg) {
System.out.println("callback1:" + msg);
}
});
System.in.read();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.examples.callback;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.examples.callback.api.CallbackListener;
import com.alibaba.dubbo.examples.callback.api.FooService;

/**
* TANHUA
*/
public class FooBarConsumer {

public static void main(String[] args) throws Exception {
String config = FooBarConsumer.class.getPackage().getName().replace('.', '/') + "/foobar-consumer.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
final FooService fooService = (FooService) context.getBean("fooService");
fooService.asyncCallInFoo("foo.bar", new CallbackListener() {
public void changed(String msg) {
System.out.println("callback1:" + msg);
}
});
System.in.read();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.alibaba.dubbo.examples.callback;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* Created by tanhua on 16/4/15.
*/
public class FooBarProvider {
public static void main(String[] args) throws Exception {
System.out.println("start service : " + args[0]);
String config = CallbackProvider.class.getPackage().getName().replace('.', '/') + "/" + args[0] +"-provider.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
context.start();
System.in.read();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.alibaba.dubbo.examples.callback.api;

/**
* Created by tanhua on 16/4/15.
*/
public interface BarService {

void asyncCallInBar(String key, CallbackListener listener);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.alibaba.dubbo.examples.callback.api;

/**
* Created by tanhua on 16/4/15.
*/
public interface FooService {

void asyncCallInFoo(String key, CallbackListener listener);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<dubbo:application name="bar-provider" />

<dubbo:registry address="zookeeper://127.0.0.1:2181" />

<dubbo:protocol name="dubbo" port="-1" />

<bean id="barService" class="com.alibaba.dubbo.examples.callback.impl.BarServiceImpl" />

<dubbo:service interface="com.alibaba.dubbo.examples.callback.api.BarService" ref="barService" connections="1" callbacks="1000">
<dubbo:method name="asyncCallInBar">
<dubbo:argument index="1" callback="true" />
<!--<dubbo:argument type="com.demo.CallbackListener" callback="true" />-->
</dubbo:method>
</dubbo:service>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<dubbo:application name="foo-provider" />

<dubbo:registry address="zookeeper://127.0.0.1:2181" />

<dubbo:protocol name="dubbo" port="-1" />

<!--<context:component-scan base-package="com.alibaba.dubbo.examples.callback" />-->

<dubbo:reference id="barService" interface="com.alibaba.dubbo.examples.callback.api.BarService" />

<dubbo:service interface="com.alibaba.dubbo.examples.callback.api.FooService" ref="fooService" connections="1" callbacks="1000">
<dubbo:method name="asyncCallInFoo">
<dubbo:argument index="1" callback="true" />
<!--<dubbo:argument type="com.demo.CallbackListener" callback="true" />-->
</dubbo:method>
</dubbo:service>

<bean id="fooService" class="com.alibaba.dubbo.examples.callback.impl.FooServiceImpl" >
<constructor-arg ref="barService"/>
</bean>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<dubbo:application name="foobar-consumer" />

<dubbo:registry address="zookeeper://127.0.0.1:2181" />

<dubbo:reference id="fooService" interface="com.alibaba.dubbo.examples.callback.api.FooService" />

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.alibaba.dubbo.examples.callback.impl;

import com.alibaba.dubbo.examples.callback.api.BarService;
import com.alibaba.dubbo.examples.callback.api.CallbackListener;

/**
* Created by tanhua on 16/4/15.
*/
public class BarServiceImpl implements BarService {

@Override
public void asyncCallInBar(final String key, final CallbackListener listener) {
new Thread(new Runnable(){
@Override
public void run() {
try {
Thread.sleep(500);//delay
} catch (Exception e) {}

listener.changed(key + ", this is bar!");
}
}).start();
}
}
Loading