diff --git a/2-advanced/dubbo-samples-context/case-configuration.yml b/2-advanced/dubbo-samples-context/case-configuration.yml index 08d43fefb1..e539ceb31c 100644 --- a/2-advanced/dubbo-samples-context/case-configuration.yml +++ b/2-advanced/dubbo-samples-context/case-configuration.yml @@ -14,11 +14,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -from: app-builtin-zookeeper.yml - -props: - project_name: dubbo-samples-context - main_class: org.apache.dubbo.samples.context.ContextProvider - zookeeper_port: 2181 - dubbo_port: 20880 +services: + direct-provider: + type: app + basedir: dubbo-samples-direct-provider + mainClass: org.apache.dubbo.samples.direct.DirectProviderApplication + direct-consumer: + type: test + basedir: dubbo-samples-direct-consumer + tests: + - "**/*IT.class" + systemProps: + - zookeeper.address=direct-provider + - zookeeper.port=2181 + - dubbo.address=direct-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - direct-provider:2181 + - direct-provider:20880 + depends_on: + - direct-provider diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/pom.xml b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/pom.xml new file mode 100644 index 0000000000..c5af02770b --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/pom.xml @@ -0,0 +1,84 @@ + + + + + + + dubbo-samples-context + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-context-consumer + + + + org.apache.dubbo + dubbo-samples-context-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/ContextConsumerApplication.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/ContextConsumerApplication.java new file mode 100644 index 0000000000..36c277e0cc --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/ContextConsumerApplication.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.samples.context; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class DirectConsumerApplication { + public static void main(String[] args) { + SpringApplication.run(ContextConsumerApplication.class,args); + } +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/Task.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/Task.java new file mode 100644 index 0000000000..56d4bb30b4 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/java/org/apache/dubbo/samples/context/Task.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.samples.context; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.context.api.DirectService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + + + +@Component +public class Task implements CommandLineRunner { + @DubboReference(interfaceClass = ContextService.class, + check = false, + group = "test", + version = "1.0.0-daily") + private DirectService directService; + + @Override + public void run(String... args) throws Exception { + String hello = directService.sayHello("world"); + System.out.println(hello); + + } +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..3e41482622 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/resources/application.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +dubbo: + application: + name: context-consumer + qos-enable: false + protocol: + name: dubbo + port: -1 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/resources/log4j.properties similarity index 100% rename from 2-advanced/dubbo-samples-context/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-context/dubbo-samples-context-consumer/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/pom.xml b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/pom.xml new file mode 100644 index 0000000000..9ac4270b19 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/pom.xml @@ -0,0 +1,33 @@ + + + + + + + + dubbo-samples-context + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-context-interface + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java new file mode 100644 index 0000000000..38cb033554 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.samples.context.api; + +public interface ContextService { + String sayHello(String name); +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java similarity index 93% rename from 2-advanced/dubbo-samples-context/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java rename to 2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java index c4690a4335..4efde5b09e 100644 --- a/2-advanced/dubbo-samples-context/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-interface/src/test/java/org/apache/dubbo/samples/context/ContextServiceIT.java @@ -26,8 +26,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath*:/spring/dubbo-context-consumer.xml"}) +@SpringBootTest +@RunWith(SpringRunner.class) public class ContextServiceIT { @Autowired @@ -42,3 +42,4 @@ public void test() throws Exception { // Assert.assertTrue(result.contains("remote: context-consumer")); } } + diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/pom.xml b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/pom.xml new file mode 100644 index 0000000000..98a4b32bef --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/pom.xml @@ -0,0 +1,81 @@ + + + + + + + dubbo-samples-context + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + + 4.0.0 + dubbo-samples-context-provider + + + + org.apache.dubbo + dubbo-samples-context-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper-curator5 + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/ContextProviderApplication.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/ContextProviderApplication.java new file mode 100644 index 0000000000..0a781c52d0 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/ContextProviderApplication.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.samples.direct.api; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class ContextProviderApplication { + public static void main(String[] args) { + SpringApplication.run(ContextProviderApplication.class, args); + } +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/impl/ContextServiceImpl.java b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/impl/ContextServiceImpl.java similarity index 91% rename from 2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/impl/ContextServiceImpl.java rename to 2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/impl/ContextServiceImpl.java index ff304e0461..e3b35aba23 100644 --- a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/impl/ContextServiceImpl.java +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/java/org/apache/dubbo/samples/context/api/impl/ContextServiceImpl.java @@ -17,10 +17,11 @@ package org.apache.dubbo.samples.context.impl; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.samples.context.api.ContextService; - +@DubboService(interfaceClass = ContextService.class, group = "test", version = "1.0.0-daily") public class ContextServiceImpl implements ContextService { @Override diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..aeeac60e7c --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/application.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +dubbo: + application: + name: context-provider + qos-enable: false + protocol: + name: dubbo + port: -1 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..d6ecd5ce34 --- /dev/null +++ b/2-advanced/dubbo-samples-context/dubbo-samples-context-provider/src/main/resources/log4j.properties @@ -0,0 +1,26 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# +# + +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/pom.xml b/2-advanced/dubbo-samples-context/pom.xml index 0eecebbcf3..08fd3c5b0b 100644 --- a/2-advanced/dubbo-samples-context/pom.xml +++ b/2-advanced/dubbo-samples-context/pom.xml @@ -8,7 +8,6 @@ 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. @@ -18,14 +17,18 @@ - org.apache.dubbo - 1.0-SNAPSHOT - 4.0.0 + + dubbo-samples-context + org.apache.dubbo + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 dubbo-samples-context - Dubbo Samples Context - Dubbo Samples Context + + 1.8 @@ -45,33 +48,33 @@ pom import - - org.apache.dubbo - dubbo-bom - ${dubbo.version} - pom - import - - - org.apache.dubbo - dubbo-dependencies-zookeeper - ${dubbo.version} - pom - + + + + + + + + + + + + + - - org.apache.dubbo - dubbo - + + + + - - org.apache.dubbo - dubbo-dependencies-zookeeper - pom - + + + + + junit @@ -80,12 +83,11 @@ test - - org.springframework - spring-test - test - - + + + + + diff --git a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextConsumer.java b/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextConsumer.java deleted file mode 100644 index 36739e0d20..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextConsumer.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.dubbo.samples.context; - -import org.apache.dubbo.samples.context.api.ContextService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class ContextConsumer { - - public static void main(String[] args) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-context-consumer.xml"); - context.start(); - ContextService contextService = context.getBean("contextService", ContextService.class); - - String hello = contextService.sayHello("world"); - System.out.println("result: " + hello); - } -} diff --git a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextProvider.java b/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextProvider.java deleted file mode 100644 index 5567d027b4..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/ContextProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.dubbo.samples.context; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - -public class ContextProvider { - - public static void main(String[] args) throws Exception { - new EmbeddedZooKeeper(2181, false).start(); - - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-context-provider.xml"); - context.start(); - - System.out.println("dubbo service started"); - new CountDownLatch(1).await(); - } -} diff --git a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/EmbeddedZooKeeper.java deleted file mode 100644 index acf5697b34..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/EmbeddedZooKeeper.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.dubbo.samples.context; - -import org.apache.zookeeper.server.ServerConfig; -import org.apache.zookeeper.server.ZooKeeperServerMain; -import org.apache.zookeeper.server.quorum.QuorumPeerConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.SmartLifecycle; -import org.springframework.util.ErrorHandler; -import org.springframework.util.SocketUtils; - -import java.io.File; -import java.lang.reflect.Method; -import java.util.Properties; -import java.util.UUID; - -/** - * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java - * - * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. - * - * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for - * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication} - * - * @author Patrick Peralta - * @author Mark Fisher - * @author David Turanski - */ -public class EmbeddedZooKeeper implements SmartLifecycle { - - /** - * Logger. - */ - private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class); - - /** - * ZooKeeper client port. This will be determined dynamically upon startup. - */ - private final int clientPort; - - /** - * Whether to auto-start. Default is true. - */ - private boolean autoStartup = true; - - /** - * Lifecycle phase. Default is 0. - */ - private int phase = 0; - - /** - * Thread for running the ZooKeeper server. - */ - private volatile Thread zkServerThread; - - /** - * ZooKeeper server. - */ - private volatile ZooKeeperServerMain zkServer; - - /** - * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. - */ - private ErrorHandler errorHandler; - - private boolean daemon = true; - - /** - * Construct an EmbeddedZooKeeper with a random port. - */ - public EmbeddedZooKeeper() { - clientPort = SocketUtils.findAvailableTcpPort(); - } - - /** - * Construct an EmbeddedZooKeeper with the provided port. - * - * @param clientPort port for ZooKeeper server to bind to - */ - public EmbeddedZooKeeper(int clientPort, boolean daemon) { - this.clientPort = clientPort; - this.daemon = daemon; - } - - /** - * Returns the port that clients should use to connect to this embedded server. - * - * @return dynamically determined client port - */ - public int getClientPort() { - return this.clientPort; - } - - /** - * Specify whether to start automatically. Default is true. - * - * @param autoStartup whether to start automatically - */ - public void setAutoStartup(boolean autoStartup) { - this.autoStartup = autoStartup; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isAutoStartup() { - return this.autoStartup; - } - - /** - * Specify the lifecycle phase for the embedded server. - * - * @param phase the lifecycle phase - */ - public void setPhase(int phase) { - this.phase = phase; - } - - /** - * {@inheritDoc} - */ - @Override - public int getPhase() { - return this.phase; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRunning() { - return (zkServerThread != null); - } - - /** - * Start the ZooKeeper server in a background thread. - *

- * Register an error handler via {@link #setErrorHandler} in order to handle - * any exceptions thrown during startup or execution. - */ - @Override - public synchronized void start() { - if (zkServerThread == null) { - zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); - zkServerThread.setDaemon(daemon); - zkServerThread.start(); - } - } - - /** - * Shutdown the ZooKeeper server. - */ - @Override - public synchronized void stop() { - if (zkServerThread != null) { - // The shutdown method is protected...thus this hack to invoke it. - // This will log an exception on shutdown; see - // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. - try { - Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); - shutdown.setAccessible(true); - shutdown.invoke(zkServer); - } - - catch (Exception e) { - throw new RuntimeException(e); - } - - // It is expected that the thread will exit after - // the server is shutdown; this will block until - // the shutdown is complete. - try { - zkServerThread.join(5000); - zkServerThread = null; - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); - logger.warn("Interrupted while waiting for embedded ZooKeeper to exit"); - // abandoning zk thread - zkServerThread = null; - } - } - } - - /** - * Stop the server if running and invoke the callback when complete. - */ - @Override - public void stop(Runnable callback) { - stop(); - callback.run(); - } - - /** - * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none - * is provided, only error-level logging will occur. - * - * @param errorHandler the {@link ErrorHandler} to be invoked - */ - public void setErrorHandler(ErrorHandler errorHandler) { - this.errorHandler = errorHandler; - } - - /** - * Runnable implementation that starts the ZooKeeper server. - */ - private class ServerRunnable implements Runnable { - - @Override - public void run() { - try { - Properties properties = new Properties(); - File file = new File(System.getProperty("java.io.tmpdir") - + File.separator + UUID.randomUUID()); - file.deleteOnExit(); - properties.setProperty("dataDir", file.getAbsolutePath()); - properties.setProperty("clientPort", String.valueOf(clientPort)); - - QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); - quorumPeerConfig.parseProperties(properties); - - zkServer = new ZooKeeperServerMain(); - ServerConfig configuration = new ServerConfig(); - configuration.readFrom(quorumPeerConfig); - - zkServer.runFromConfig(configuration); - } - catch (Exception e) { - if (errorHandler != null) { - errorHandler.handleError(e); - } - else { - logger.error("Exception running embedded ZooKeeper", e); - } - } - } - } - -} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java b/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java deleted file mode 100644 index 52b205bc21..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/java/org/apache/dubbo/samples/context/api/ContextService.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.dubbo.samples.context.api; - -public interface ContextService { - public String sayHello(String name); -} diff --git a/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-consumer.xml b/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-consumer.xml deleted file mode 100644 index 21e1087a7c..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-consumer.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-provider.xml b/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-provider.xml deleted file mode 100644 index 1e1e691e38..0000000000 --- a/2-advanced/dubbo-samples-context/src/main/resources/spring/dubbo-context-provider.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - -