Permalink
Browse files

Initial work

  • Loading branch information...
pmuir committed Nov 9, 2011
0 parents commit 561b6a3b2a6743ae0e1e8562a38e75f764435ca0
@@ -0,0 +1,5 @@
+.idea
+.classpath
+.project
+.settings
+target
@@ -0,0 +1,169 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.infinispan.labs</groupId>
+ <artifactId>lab1</artifactId>
+ <packaging>war</packaging>
+ <version>1.0</version>
+
+
+ <url>http://jboss.org/infinispan</url>
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License</name>
+ <url>http://www.gnu.org/copyleft/lesser.html</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <properties>
+ <!-- Explicitly declaring the source encoding eliminates the following
+ message: -->
+ <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+ resources, i.e. build is platform dependent! -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <infinispan.version>5.1.0.BETA1</infinispan.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including
+ a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
+ a collection) of artifacts. We use this here so that we always get the correct
+ versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can
+ read this as the JBoss stack of the Java EE 6 Web Profile APIs), and we use
+ version 2.0.0.Final which is the latest release of the stack. You can actually
+ use this stack with any version of JBoss AS that implements Java EE 6, not
+ just JBoss AS 7! -->
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-web-6.0</artifactId>
+ <version>2.0.0.Final</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-core</artifactId>
+ <version>${infinispan.version}</version>
+ </dependency>
+
+ <!-- Infinispan dependency -->
+ <dependency>
+ <groupId>org.infinispan</groupId>
+ <artifactId>infinispan-cdi</artifactId>
+ <version>${infinispan.version}</version>
+ </dependency>
+
+ <!-- Import the CDI API, we use provided scope as the API is included
+ in JBoss AS 7 -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the Common Annotations API (JSR-250), we use provided scope
+ as the API is included in JBoss AS 7 -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.annotation</groupId>
+ <artifactId>jboss-annotations-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Import the Servlet API, we use provided scope as the API is included
+ in JBoss AS 7 -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.servlet</groupId>
+ <artifactId>jboss-servlet-api_3.0_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec.javax.ejb</groupId>
+ <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <!-- Set the name of the war, used as the context root when the app
+ is deployed -->
+ <finalName>lab1</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1.1</version>
+ <configuration>
+ <!-- Java EE 6 doesn't require web.xml, Maven needs to catch
+ up! -->
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <archive>
+ <manifestEntries>
+ <Dependencies>org.infinispan export</Dependencies>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <!-- JBoss AS plugin to deploy war -->
+ <plugin>
+ <groupId>org.jboss.as.plugins</groupId>
+ <artifactId>jboss-as-maven-plugin</artifactId>
+ <version>7.0.2.Final</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>jboss-public-repository</id>
+ <activation>
+ <property>
+ <name>jboss-public-repository</name>
+ <value>!false</value>
+ </property>
+ </activation>
+ <repositories>
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</project>
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other
+ * contributors as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.labs.lab1;
+
+import javax.enterprise.inject.Produces;
+
+import org.infinispan.cdi.ConfigureCache;
+import org.infinispan.config.Configuration;
+import org.infinispan.eviction.EvictionStrategy;
+import org.infinispan.labs.lab1.service.TicketAllocationCache;
+
+/**
+ * Cache definitions
+ *
+ * @author Kevin Pollet <pollet.kevin@gmail.com> (C) 2011
+ */
+public class Resources {
+
+ /**
+ * <p>This producer defines the ticket allocation cache configuration.</p>
+ *
+ * <p>This cache will have:
+ * <ul>
+ * <li>a maximum of 4 entries</li>
+ * <li>use the strategy FIFO for eviction</li>
+ * </ul>
+ * </p>
+ *
+ */
+ @TicketAllocationCache
+ @ConfigureCache("ticket-allocation-cache")
+ @Produces
+ public Configuration configureCache() {
+ return new Configuration().fluent()
+ .eviction().strategy(EvictionStrategy.FIFO).maxEntries(4)
+ .build();
+ }
+
+
+
+}
@@ -0,0 +1,24 @@
+package org.infinispan.labs.lab1;
+
+import javax.inject.Inject;
+
+import org.infinispan.labs.lab1.service.TicketService;
+
+public class TicketPopulator {
+
+ private final TicketService tickets;
+
+ @Inject
+ public TicketPopulator(TicketService tickets) {
+ this.tickets = tickets;
+ }
+
+ public void populate() {
+ tickets.allocateTicket("pmuir", "Devoxx presents...");
+ tickets.allocateTicket("sanne", "Devoxx presents...");
+ tickets.allocateTicket("mmarkus", "Devoxx presents...");
+ tickets.allocateTicket("manik", "Best of Abba");
+ tickets.allocateTicket("dan", "Cher's greatest hits");
+ }
+
+}
@@ -0,0 +1,38 @@
+package org.infinispan.labs.lab1.model;
+
+/**
+ * Model object which shows allocation of ticket to user
+ *
+ * @author Pete Muir
+ *
+ */
+public class TicketAllocation {
+
+ // The name of the person the ticket is alloacted to
+ private String allocatedTo;
+
+ // The name of the event the ticket is for
+ private String event;
+
+ public TicketAllocation(String allocatedTo, String event) {
+ this.allocatedTo = allocatedTo;
+ this.event = event;
+ }
+
+ public String getAllocatedTo() {
+ return allocatedTo;
+ }
+
+ public void setAllocatedTo(String name) {
+ this.allocatedTo = name;
+ }
+
+ public String getEvent() {
+ return event;
+ }
+
+ public void setEvent(String eventName) {
+ this.event = eventName;
+ }
+
+}
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other
+ * contributors as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.labs.lab1.service;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.infinispan.labs.lab1.TicketPopulator;
+import org.infinispan.labs.lab1.model.TicketAllocation;
+
+/**
+ * <p>The ticket allocator.</p>
+ *
+ * <p>Facade over the ticket allocation backend.</p>
+ *
+ * @author Pete Muir
+ */
+@Named
+@ApplicationScoped
+public class SimpleTicketService implements TicketService {
+
+ private final Map<String, List<TicketAllocation>> tickets;
+
+ public SimpleTicketService() {
+ this.tickets = new HashMap<String, List<TicketAllocation>>();
+ }
+
+ @Inject
+ public void populate(TicketPopulator populator) {
+ populator.populate();
+ }
+
+ public void allocateTicket(String allocatedTo, String event) {
+
+ if (this.tickets.containsKey(event)) {
+ this.tickets.get(event).add(new TicketAllocation(allocatedTo, event));
+ } else {
+ List<TicketAllocation> l = new ArrayList<TicketAllocation>();
+ l.add(new TicketAllocation(allocatedTo, event));
+ this.tickets.put(event, l);
+ }
+
+ }
+
+ public List<TicketAllocation> getTicketsAllocated(String event) {
+ return tickets.get(event);
+ }
+
+ public Set<String> getEvents() {
+ return tickets.keySet();
+ }
+
+ public void clearAllocations() {
+ tickets.clear();
+ }
+
+}
Oops, something went wrong.

0 comments on commit 561b6a3

Please sign in to comment.