210 likes | 363 Views
JavaONE 2007. Agenda. Reverse Ajax - DWR GlassFish V3 Effective Java Reloaded: This Time it's NOT for Real. Reverse Ajax - DWR. Joe Walker/Geert Bevin (TS-6410) New feature in DWR 2.0 CommunityOne: ICEfaces and Ajax Push. Reversed Ajax – DWR: Overview.
E N D
JavaONE 2007 javaONE 2007 - Kjartan Aanestad (Objectware)
Agenda • Reverse Ajax - DWR • GlassFish V3 • Effective Java Reloaded: This Time it's NOT for Real javaONE 2007 - Kjartan Aanestad (Objectware)
Reverse Ajax - DWR • Joe Walker/Geert Bevin (TS-6410) • New feature in DWR 2.0 • CommunityOne: ICEfaces and Ajax Push javaONE 2007 - Kjartan Aanestad (Objectware)
Reversed Ajax – DWR:Overview • The ability to asynchronously send data from a web-server to a browser javaONE 2007 - Kjartan Aanestad (Objectware)
Reversed Ajax – DWR:Overview • Supports 3 methods of pushing the data to the browser: • Polling – Browser makes regular request to the server • Piggyback – Puts the response with the next request • Comet (aka Long lived http) – Keeps the communication channel open to pass down information when time comes. javaONE 2007 - Kjartan Aanestad (Objectware)
Reversed Ajax – DWR:”live” coding demo javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3 • Jerome Dochez (TS-6503) • Loosely based on the work for JSR 277 (Java Module System ) • Due in Java SE 7 • Architecture based on IoC, modules and maven 2 javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Module subsystem • The module subsystem is called HK2 (Hundred Kb Kernel) • Module system based on maven • Identified by name and version • One classloader per module of 1 to n jars • Exports a subset of its content (Service Provider Interface) • Imports other modules (listed in manifest file) javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Module instances • Modules identified by module instances at runtime • 2 classloaders (public/private) • Runtime network of class loaders javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Repository • Repositories hold modules • Add and remove at runtime • Different types supported • Directory based • Maven • Modules can be added/removed/updated from repositories javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Bootstrapping • Module subsystems can bootstrap itself • No need to define a classpath at invocation • Packaged in a jar • Implement the ApplicationStartup interface • Declare dependencies in manifest javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Build System: Maven • Each module is build from a maven project (pom.xml)<groupId>com.sun.enterprise.glassfish</groupId><artifactId>gf-web-connector</artifactId><version>1.2.1</version><packaging>hk2-jar</packaging> • Running GlassFish retrieves the modules from the maven repository$ mvn gf:run javaONE 2007 - Kjartan Aanestad (Objectware)
GlassFish V3:Services • GlassFish V3 use extensively Services to identify extension points like • Application containers like web-app, Jruby, Phobos..) • Administrative commands • Services in V3: • Interfaces are declared with @Contract • Implementations are declared with @Service @Contract public interface AdminCommand {...} @Service(name=”deploy”) public class DeployCommand implements AdminCommand {...} javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded: This Time it's NOT for Real • Joshua Bloch (TS-2689) • Effective Java still hasn’t been reloaded - It will be done later this year for sure.. • Object creation • Generics javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Object creation • Static factories Map<String, List<String>> m = new HashMap<String, List<String>>(); Map<String, List<String>> m = HashMap.newInstance(); • Regrettably HashMaphas no such method (yet) • write your own, your generic classes can and should: public static <K, V> HashMap<K, V> newInstance() { return new HashMap<K, V>(); } javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Object creation • Builder pattern • Ugly when constructors have many optional parametersnew NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate, 15 more optional params!); • Builder constructor takes all required params • One setter for each optional parameter • Setter returns the builder to allow for chaining NutritionFacts locoCola = new NutritionFacts.Builder(240, 8) .sodium(30).carbohydrate(28).build(); javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Object creation public class NutritionFacts { public static class Builder { public Builder(int servingSize, int servings) { this.servingSize = servingSize; this.servings = servings; } public Builder calories(int val) { calories = val; return this; } ... // 15 more setters public NutritionFacts build() { return new NutritionFacts(this); } } private NutritionFacts(Builder builder) { .. } } javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Generics – bounded wildcards • Use bounded wildcards to increase applicability of APIs public interface Shop<T> { void buy(int numToBuy, Collection<T> myColl); void sell(Collection<T> myLot); } • Collection subtyping doesn’t work! public interface Shop<T> { void buy(int numToBuy, Collection<? super T> myColl); void sell(Collection<? extends T> myLot); } • Use <? extends T> when parameterized instance is a T producer (“for read/input”) • Use <? super T> when parameterized instance is a T consumer (“for write/output”) javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Generics – wildcard capture • Control Wildcard-Capture • Type system doesn’t know captured types are identical public static void rotate(List<?> list) { if (list.size() == 0) return; list.add(list.remove(0)); } • Solution: public static void rotate(List<?> list) { rotateHelper(list); } // Generic helper method captures wildcard once private static <E> void rotateHelper(List<E> list) { if (list.size() == 0) return; list.add(list.remove(0)); } javaONE 2007 - Kjartan Aanestad (Objectware)
Effective Java Reloaded:Generics – miscellania • final is the new private • Minimizes mutability • Clearly thread-safe—one less thing to worry about • Use the @Override annotation every time you want to override • Avoid overriding my mistake javaONE 2007 - Kjartan Aanestad (Objectware)
JavaONE 2007 Kjartan Aanestad - Objectware javaONE 2007 - Kjartan Aanestad (Objectware)