Author: cutting
Date: Mon Sep 26 21:14:35 2011
New Revision: 1176060
URL: http://svn.apache.org/viewvc?rev=1176060&view=rev
Log:
AVRO-890: Java: Add Maven archetype for creating Avro service projects.
Contributed by Stephen Gargan.
Added:
avro/trunk/lang/java/archetypes/ (with props)
avro/trunk/lang/java/archetypes/avro-service-archetype/ (with props)
avro/trunk/lang/java/archetypes/avro-service-archetype/pom.xml
avro/trunk/lang/java/archetypes/avro-service-archetype/src/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/pom.xml
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/order-service.avpr
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceEndpoint.java
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/logback.xml
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/archetype.properties
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/goal.txt
avro/trunk/lang/java/archetypes/pom.xml
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/pom.xml
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1176060&r1=1176059&r2=1176060&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Sep 26 21:14:35 2011
@@ -25,6 +25,9 @@ Avro 1.6.0 (unreleased)
AVRO-893. C: Avro data file functions using new value interface.
(dcreager)
+ AVRO-890: Java: Add Maven archetype for creating Avro service
+ projects. (Stephen Gargan via cutting)
+
OPTIMIZATIONS
AVRO-853: Java: Cache Schema hash codes. (cutting)
Propchange: avro/trunk/lang/java/archetypes/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Sep 26 21:14:35 2011
@@ -0,0 +1 @@
+target
Propchange: avro/trunk/lang/java/archetypes/avro-service-archetype/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Sep 26 21:14:35 2011
@@ -0,0 +1 @@
+target
Added: avro/trunk/lang/java/archetypes/avro-service-archetype/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/pom.xml?rev=1176060&view=auto
==============================================================================
--- avro/trunk/lang/java/archetypes/avro-service-archetype/pom.xml (added)
+++ avro/trunk/lang/java/archetypes/avro-service-archetype/pom.xml Mon Sep 26
21:14:35 2011
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>avro-archetypes-parent</artifactId>
+ <groupId>org.apache.avro</groupId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>avro-service-archetype</artifactId>
+ <name>Apache Avro Maven Service Archetype</name>
+ <description>Archetype that generates a simple example Avro
service</description>
+ <packaging>maven-archetype</packaging>
+</project>
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml?rev=1176060&view=auto
==============================================================================
--- avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
(added)
+++ avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/pom/pom.xml
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,115 @@
+<?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>\${groupId}</groupId>
+ <artifactId>\${artifactId}</artifactId>
+ <packaging>jar</packaging>
+ <version>\${version}</version>
+ <name>Simple Avro Ordering Service</name>
+ <properties>
+ <avro-version>${project.version}</avro-version>
+ <jackson-version>1.8.4</jackson-version>
+ <junit.version>4.8.1</junit.version>
+ <logback.version>0.9.29</logback.version>
+ <slf4j.version>1.6.2</slf4j.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro</artifactId>
+ <version>\${avro-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-ipc</artifactId>
+ <version>\${avro-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>\${jackson-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>\${jackson-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>\${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>\${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>\${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-maven-plugin</artifactId>
+ <version>${avro-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <!-- By default generates classes from all Protocol (.avpr)
files found in 'src/main/avro' -->
+ <goal>protocol</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-ipc</artifactId>
+ <version>\${avro-version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <excludes>
+ <exclude>%regex[.*.integration.*]</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>%regex[.*.integration.*]</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archetype-descriptor
+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0
http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+ name="simple-avro-ordering-service"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/avro</directory>
+ <includes>
+ <include>**/*.avpr</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</archetype-descriptor>
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/pom.xml?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/pom.xml
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/pom.xml
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,115 @@
+<?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>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <packaging>jar</packaging>
+ <version>${version}</version>
+ <name>Simple Avro Ordering Service</name>
+ <properties>
+ <avro-version>1.6.0-SNAPSHOT</avro-version>
+ <jackson-version>1.8.4</jackson-version>
+ <junit.version>4.8.1</junit.version>
+ <logback.version>0.9.29</logback.version>
+ <slf4j.version>1.6.2</slf4j.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro</artifactId>
+ <version>${avro-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-ipc</artifactId>
+ <version>${avro-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-core-asl</artifactId>
+ <version>${jackson-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>${jackson-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-maven-plugin</artifactId>
+ <version>${avro-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <!-- By default generates classes from all Protocol (.avpr)
files found in 'src/main/avro' -->
+ <goal>protocol</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.avro</groupId>
+ <artifactId>avro-ipc</artifactId>
+ <version>${avro-version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <excludes>
+ <exclude>%regex[.*.integration.*]</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>%regex[.*.integration.*]</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/order-service.avpr
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/order-service.avpr?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/order-service.avpr
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/avro/order-service.avpr
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,46 @@
+{
+ "namespace":"${package}.service",
+ "protocol": "OrderProcessingService",
+ "doc": "Protocol to submit customer Orders",
+ "types": [
+ {
+ "name": "Item", "type": "record",
+ "fields": [
+ {"name": "name", "type": "string"},
+ {"name": "sku", "type": "long"},
+ {"name": "quantity", "type": "int"}
+ ]
+ },
+ {
+ "name": "Order", "type": "record",
+ "fields": [
+ {"name": "customerId", "type": "long"},
+ {"name": "orderId", "type": "long"},
+ {"name": "orderItems", "type": {"type": "array", "items":
"Item"}}
+ ]
+ },
+ {
+ "name": "Confirmation", "type": "record",
+ "fields": [
+ {"name": "customerId", "type": {"type": "long"}},
+ {"name": "orderId", "type": "long"},
+ {"name": "estimatedCompletion", "type": "long"}
+ ]
+ },
+ {
+ "name": "OrderFailure", "type": "error",
+ "fields": [
+ {"name": "message", "type": "string"}
+ ]
+ }
+ ],
+
+ "messages": {
+ "submitOrder": {
+ "doc": "Submit an Order",
+ "request": [{"name": "order", "type": "Order"}],
+ "response": "Confirmation",
+ "errors": ["OrderFailure"]
+ }
+ }
+}
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,32 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package}.service;
+
+import org.apache.avro.AvroRemoteException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ${package}.service.Confirmation;
+import ${package}.service.Order;
+import ${package}.service.OrderFailure;
+import ${package}.service.OrderProcessingService;
+
+/**
+ * <code>SimpleOrderService</code> is a simple example implementation of an
Avro service generated from the
+ * order-service.avpr protocol definition.
+ */
+public class SimpleOrderService implements OrderProcessingService {
+
+ private Logger log = LoggerFactory.getLogger(SimpleOrderService.class);
+
+ @Override
+ public Confirmation submitOrder(Order order) throws
AvroRemoteException, OrderFailure {
+ log.info("Received order for '{}' items from customer with id
'{}'",
+ new Object[] {order.getOrderItems().size(),
order.getCustomerId() });
+
+ long estimatedCompletion = System.currentTimeMillis() + (5 * 60
* 60);
+ return
Confirmation.newBuilder().setCustomerId(order.getCustomerId())
+
.setEstimatedCompletion(estimatedCompletion).setOrderId(order.getOrderId()).build();
+ }
+}
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,61 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package}.transport;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import org.apache.avro.AvroRemoteException;
+import org.apache.avro.ipc.NettyTransceiver;
+import org.apache.avro.ipc.Transceiver;
+import org.apache.avro.ipc.specific.SpecificRequestor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ${package}.service.Confirmation;
+import ${package}.service.Order;
+import ${package}.service.OrderFailure;
+import ${package}.service.OrderProcessingService;
+
+/**
+ * <code>SimpleOrderServiceClient</code> is a basic client for the Netty
backed {@link OrderProcessingService}
+ * implementation.
+ */
+public class SimpleOrderServiceClient implements OrderProcessingService {
+
+ private static final Logger log =
LoggerFactory.getLogger(SimpleOrderServiceEndpoint.class);
+
+ private InetSocketAddress endpointAddress;
+
+ private Transceiver transceiver;
+
+ private OrderProcessingService service;
+
+ public SimpleOrderServiceClient(InetSocketAddress endpointAddress) {
+ this.endpointAddress = endpointAddress;
+ }
+
+ public synchronized void start() throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("Starting Simple Ordering Netty client on
'{}'", endpointAddress);
+ }
+ transceiver = new NettyTransceiver(endpointAddress);
+ service =
SpecificRequestor.getClient(OrderProcessingService.class, transceiver);
+ }
+
+ public void stop() throws IOException {
+ if (log.isInfoEnabled()) {
+ log.info("Stopping Simple Ordering Netty client on
'{}'", endpointAddress);
+ }
+ if (transceiver != null && transceiver.isConnected()) {
+ transceiver.close();
+ }
+ }
+
+ @Override
+ public Confirmation submitOrder(Order order) throws
AvroRemoteException, OrderFailure {
+ return service.submitOrder(order);
+ }
+
+}
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceEndpoint.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceEndpoint.java?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceEndpoint.java
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceEndpoint.java
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,49 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package}.transport;
+
+import java.net.InetSocketAddress;
+
+import ${package}.service.SimpleOrderService;
+import org.apache.avro.ipc.NettyServer;
+import org.apache.avro.ipc.Server;
+import org.apache.avro.ipc.specific.SpecificResponder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ${package}.service.OrderProcessingService;
+
+/**
+ * <code>SimpleOrderProcessingServer</code> provides a very basic example
Netty endpoint for the
+ * {@link SimpleOrderService} implementation
+ */
+public class SimpleOrderServiceEndpoint {
+
+ private static final Logger log =
LoggerFactory.getLogger(SimpleOrderServiceEndpoint.class);
+
+ private InetSocketAddress endpointAddress;
+
+ private Server service;
+
+ public SimpleOrderServiceEndpoint(InetSocketAddress endpointAddress) {
+ this.endpointAddress = endpointAddress;
+ }
+
+ public synchronized void start() throws Exception {
+ if (log.isInfoEnabled()) {
+ log.info("Starting Simple Ordering Netty Server on
'{}'", endpointAddress);
+ }
+
+ SpecificResponder responder = new
SpecificResponder(OrderProcessingService.class, new SimpleOrderService());
+ service = new NettyServer(responder, endpointAddress);
+ service.start();
+ }
+
+ public synchronized void stop() throws Exception {
+ if (log.isInfoEnabled()) {
+ log.info("Stopping Simple Ordering Server on '{}'",
endpointAddress);
+ }
+ service.start();
+ }
+}
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/logback.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/logback.xml?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/logback.xml
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/resources/logback.xml
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,14 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n</pattern>
+ </encoder>
+ </appender>
+ <root level="info">
+ <appender-ref ref="console" />
+ </root>
+</configuration>
\ No newline at end of file
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/test/java/integration/SimpleOrderServiceIntegrationTest.java
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,69 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package}.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import ${package}.transport.SimpleOrderServiceEndpoint;
+import ${package}.transport.SimpleOrderServiceClient;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import ${package}.service.Confirmation;
+import ${package}.service.Item;
+import ${package}.service.Order;
+
+/**
+ * <code>SimpleOrderServiceIntegrationTest</code> runs as part of the
Integration phase of the build and is
+ * meant for end to end service testing.
+ */
+public class SimpleOrderServiceIntegrationTest {
+
+ private static SimpleOrderServiceEndpoint service;
+ private static SimpleOrderServiceClient client;
+
+ @Test
+ public void simpleRoundTripTest() throws Exception {
+ Order simpleOrder = createOrder();
+ Confirmation c = client.submitOrder(simpleOrder);
+
+ assertEquals(c.getOrderId(), simpleOrder.getOrderId());
+ assertEquals(c.getCustomerId(), simpleOrder.getCustomerId());
+ assertTrue(c.getEstimatedCompletion() > 0);
+ }
+
+ @BeforeClass
+ public static void setupTransport() throws Exception {
+ InetSocketAddress endpointAddress = new
InetSocketAddress("0.0.0.0", 12345);
+ service = new SimpleOrderServiceEndpoint(endpointAddress);
+ client = new SimpleOrderServiceClient(endpointAddress);
+
+ service.start();
+ client.start();
+ }
+
+ @AfterClass
+ public static void shutdownTransport() throws Exception {
+ client.stop();
+ service.stop();
+ }
+
+ public Order createOrder() {
+ return
Order.newBuilder().setOrderId(1).setCustomerId(1).setOrderItems(createItems()).build();
+ }
+
+ public List<Item> createItems() {
+ List<Item> items = new ArrayList<Item>();
+ for (int x = 0; x < 5; x++)
+ items.add(Item.newBuilder().setName("Item-" +
x).setQuantity(x + 1).setSku(1230 + x).build());
+ return items;
+ }
+
+}
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/archetype.properties
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/archetype.properties?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/archetype.properties
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/archetype.properties
Mon Sep 26 21:14:35 2011
@@ -0,0 +1,6 @@
+#Mon Sep 19 23:10:41 IST 2011
+version=0.1-SNAPSHOT
+groupId=org.apache.avro.example
+artifactId=simple-service
+package=org.apache.avro.example
+
Added:
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/goal.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/goal.txt?rev=1176060&view=auto
==============================================================================
---
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/goal.txt
(added)
+++
avro/trunk/lang/java/archetypes/avro-service-archetype/src/test/integration/projects/basic/goal.txt
Mon Sep 26 21:14:35 2011
@@ -0,0 +1 @@
+integration-test
Added: avro/trunk/lang/java/archetypes/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/archetypes/pom.xml?rev=1176060&view=auto
==============================================================================
--- avro/trunk/lang/java/archetypes/pom.xml (added)
+++ avro/trunk/lang/java/archetypes/pom.xml Mon Sep 26 21:14:35 2011
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>avro-parent</artifactId>
+ <groupId>org.apache.avro</groupId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>avro-archetypes-parent</artifactId>
+ <name>Apache Avro Maven Archetypes</name>
+ <description>Archetypes parent defining configuration for generating
archetype poms with the correct Avro version</description>
+ <packaging>pom</packaging>
+ <modules>
+ <module>avro-service-archetype</module>
+ </modules>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.archetype.version>2.1</maven.archetype.version>
+ </properties>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.archetype</groupId>
+ <artifactId>archetype-packaging</artifactId>
+ <version>${maven.archetype.version}</version>
+ </extension>
+ </extensions>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>${maven.archetype.version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <!-- Creates a pom.xml for the archetype that references the current
avro version -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.5</version>
+ <executions>
+ <execution>
+ <id>copy-pom-with-building-version</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+
<outputDirectory>src/main/resources/archetype-resources</outputDirectory>
+ <escapeString>\</escapeString>
+ <resources>
+ <resource>
+ <directory>src/main/pom/</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>pom.xml</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-archetype-integration-resources</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>verify</phase>
+ <configuration>
+ <outputDirectory>target/test-classes/</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/test/integration</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-archetype-plugin</artifactId>
+ <version>${maven.archetype.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ <phase>install</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Modified: avro/trunk/lang/java/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/pom.xml?rev=1176060&r1=1176059&r2=1176060&view=diff
==============================================================================
--- avro/trunk/lang/java/pom.xml (original)
+++ avro/trunk/lang/java/pom.xml Mon Sep 26 21:14:35 2011
@@ -405,6 +405,7 @@
<module>tools</module>
<module>mapred</module>
<module>protobuf</module>
+ <module>archetypes</module>
</modules>
</project>