-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2edcdd2
commit 919df92
Showing
305 changed files
with
42,708 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?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.mksmart.squire</groupId> | ||
<artifactId>WebSquire</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<name>WebSquire</name> | ||
|
||
<properties> | ||
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-server-linking</artifactId> | ||
<version>1.19.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-json</artifactId> | ||
<version>1.19.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-web-api</artifactId> | ||
<version>7.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.4</version> | ||
<type>jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-core</artifactId> | ||
<version>5.4.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-spellchecker</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.jena</groupId> | ||
<artifactId>apache-jena-libs</artifactId> | ||
<type>pom</type> | ||
<version>3.0.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.googlecode.json-simple</groupId> | ||
<artifactId>json-simple</artifactId> | ||
<version>1.1</version> | ||
</dependency> | ||
|
||
|
||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.3.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.ektorp</groupId> | ||
<artifactId>org.ektorp</artifactId> | ||
<version>1.4.2</version> | ||
<optional>true</optional> | ||
<exclusions> | ||
<exclusion> <!-- declare the exclusion here --> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</exclusion> | ||
<exclusion> <!-- declare the exclusion here --> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient-cache</artifactId> | ||
</exclusion> | ||
<exclusion> <!-- declare the exclusion here --> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
</exclusion> | ||
|
||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-suggest</artifactId> | ||
<version>5.0.0</version> | ||
<type>jar</type> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
<compilerArguments> | ||
<endorseddirs>${endorsed.dir}</endorseddirs> | ||
</compilerArguments> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.6</version> | ||
<executions> | ||
<execution> | ||
<phase>validate</phase> | ||
<goals> | ||
<goal>copy</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${endorsed.dir}</outputDirectory> | ||
<silent>true</silent> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-endorsed-api</artifactId> | ||
<version>7.0</version> | ||
<type>jar</type> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package future.test; | ||
|
||
import java.util.LinkedList; | ||
|
||
/** | ||
* | ||
* @author carloallocca | ||
*/ | ||
public class App { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
|
||
LinkedList<Integer> list = new LinkedList<Integer>(); | ||
|
||
final Processor processor = new Processor(1, list); | ||
|
||
Thread t1 = new Thread(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
processor.produce(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
Thread t2 = new Thread(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
processor.consume(); | ||
System.out.println("[App::main]Ten More Results..."); | ||
System.out.println(processor.getUpdatedList().toString()); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
t1.start(); | ||
t2.start(); | ||
|
||
// t1.join(); | ||
// t2.join(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package future.test; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* | ||
* @author carloallocca | ||
*/ | ||
public class FactorialCalculator implements Callable { | ||
|
||
private final int number; | ||
|
||
public FactorialCalculator(int number) { | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public Object call() throws Exception { | ||
|
||
long output = 0; | ||
try { | ||
output = factorial(number); | ||
|
||
} catch (InterruptedException ex) { | ||
Logger.getLogger(FactorialCalculator.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
return output; | ||
} | ||
|
||
private long factorial(int number) throws InterruptedException { | ||
if (number < 0) { | ||
throw new IllegalArgumentException("Number must be greater than zero"); | ||
} | ||
|
||
long result = 1; | ||
while (number > 0) { | ||
Thread.sleep(1); // adding delay for example | ||
result = result * number; | ||
number--; | ||
} | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package future.test; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
|
||
/** | ||
* | ||
* @author carloallocca | ||
*/ | ||
public class FutureDemo { | ||
|
||
private static final ExecutorService threadpool = Executors.newFixedThreadPool(3); | ||
|
||
public static void main(String args[]) throws InterruptedException, ExecutionException { | ||
|
||
FactorialCalculator task = new FactorialCalculator(100); | ||
System.out.println("Submitting Task ..."); | ||
Future future = threadpool.submit(task); | ||
|
||
System.out.println("Task is submitted"); | ||
|
||
|
||
while (!future.isDone()) { | ||
System.out.println("Task is not completed yet...."); | ||
// System.out.println("The current value is...."+future.get()); | ||
|
||
Thread.sleep(1); //sleep for 1 millisecond before checking again | ||
|
||
|
||
} | ||
System.out.println("Task is completed, let's check result"); | ||
long factorial = (long) future.get(); | ||
System.out.println("Factorial of 10 is : " + factorial); | ||
|
||
threadpool.shutdown(); | ||
|
||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.