AWS Concepts

This course provides practical and conceptual introduction to the concepts of Cloud Computing and Amazon Web Services.

  • Have the conceptual foundation to move forward onto more advanced AWS courses
  • Be more prepared to tackle the more complex technical concepts and terminology
Exceptions in the life: Checked vs Unchecked problems

In Java, as well as in your life, there two type of exception:

  1. checked exception that are the expected problems
  2. unchecked exception, that are the unexpected problems.

As in the life, for the expected events you are prepared because you plain to have that problem. So you are organized to intercept and block that problem. For example, if you are a student, or you have been a student, you know that your teacher could exam you. To avoid a negative
vote, or problem with you parents , you (theoretically) study. If you don’t study enough you could have a bad vote. But basically you are aware.

In Java is exactly the same, apart from the fact that problems are named Exception. You, and also the compiler, know that you can expect an exception calling a method and then you prevent that exception intercepting it with a try-catch-finally block.

int vote;
try{
vote=teacher.exams(you);
}
catch(NoStudiedException nse){
vote=VOTE.Very_Bad;
}
finally{
register.setVote(you,vote);
}

In Java you are aware because exists the throws clause that forces you to face up to your problem.

The exams method of Teacher class is like below:

public int exams(Student student) throws NoStudiedException{

}

But, unfortunately, there are no just checked exception. We can have also unexpected exception that you and the compiler are not aware, for example RuntimeException, ArrayIndexOutOfBoundException, but above all: NullPointerException.

They are all problems you could never have imagined it could happen to you. They are Unchecked.

All exception under Error and RuntimeException classes are Unchecked

You have to know the difference even because there are some framework that have different behavior based on checked and unchecked events.

For example JPA, that is in charge of transactions, makes an automatic rollback just in case of unchecked exception, BUT doesn’t make the same for the checked ones. It means that, if you use JPA and you want rollback when a CheckedException happens, then you have manually rollback out, adding the clause “rollbackFor=<CheckedException>.class” above the method. If you don’t use JPA and his children/nephew then pretend I did not say anything…

Design pattern for chess masters

Today I played chess with a colleague, I made a couple of very good forks.
But he put me in trouble with a good opening.

Do you know what openings, forks and also nailing are in chess?

They are very precise schemes, they have the names (Gambetto di donna, Sicilian defense, English match, French defense,…), well-defined patterns, every good chess player must know in memory.

These chess pattern are grouped into different families like opening, finals, and so on.

They are very precise moves, which you can always repeat, in every game or several times in a game, to which names have been assigned and they bring a very precise benefits.

So, what tactics are for chess, then Design pattern are for OO Design:

  • a general design solution
  • to a repeatable situation 
  • with a description 
  • a very precise schema
  • and that you have to know
  • grouped in different families: creational, structural and behavioral

The general design situation means that, when you are designing an object oriented software, there is a well know way to do it for each type of component and layer.

Repeatable means that the situations are the same for each system you can design and so you can use again that model

With a description means that that situation has a name

Very precise schema means that there is a design model already ready to use and that you could adapt it to your component

You have to know means that you should study them so that you can apply in every situation

The different families are about the different type of design situations

  • Creational are abut the way in which objects are created
  • Structural pattern identify a simple way to realize relationships among entities
  • Behavioral provide solution for the better interaction between objects

Example of Creational pattern:

  • Abstract Factory pattern: a class requests the objects it requires from a factory object instead of creating the objects directly
  • Factory method pattern: centralize creation of an object of a specific type choosing one of several implementations
  • Builder pattern: separate the construction of a complex object from its representation so that the same construction process can create different representations
  • Dependency Injection pattern: a class accepts the objects it requires from an injector instead of creating the objects directly
  • Lazy initialization pattern: tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed
  • Object pool pattern: avoid expensive acquisition and release of resources by recycling objects that are no longer in use
  • Prototype pattern: used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects
  • Singleton pattern: restrict instantiation of a class to one object

Example of Structural pattern:

  • Adapter pattern: ‘adapts’ one interface for a class into one that a client expects
  • Bridge pattern: decouple an abstraction from its implementation so that the two can vary independently
  • Composite pattern: a tree structure of objects where every object has the same interface
  • Decorator pattern: add additional functionality to a class at runtime where subclassing would result in an exponential rise of new classes
  • Extensibility pattern: a.k.a. Framework – hide complex code behind a simple interface
  • Facade pattern: create a simplified interface of an existing interface to ease usage for common tasks
  • Flyweight pattern: a large quantity of objects share a common properties object to save space
  • Pipes and filters: a chain of processes where the output of each process is the input of the next
  • Proxy pattern: a class functioning as an interface to another thing

Example of Behavioral pattern:

  • Chain of responsibility pattern: Command objects are handled or passed on to other objects by logic-containing processing objects
  • Command pattern: Command objects encapsulate an action and its parameters
  • Interpreter pattern: Implement a specialized computer language to rapidly solve a specific set of problems
  • Iterator pattern: Iterators are used to access the elements of an aggregate object sequentially without exposing its underlying representation
  • Mediator pattern: Provides a unified interface to a set of interfaces in a subsystem
  • Memento pattern: Provides the ability to restore an object to its previous state (rollback)
  • Null object pattern: Designed to act as a default value of an object
  • Observer pattern: a.k.a. Publish/Subscribe or Event Listener. Objects register to observe an event that may be raised by another object
  • State pattern: A clean way for an object to partially change its type at runtime
  • Strategy pattern: Algorithms can be selected on the fly, using composition
  • Template method pattern: Describes the program skeleton of a program; algorithms can be selected on the fly, using inheritance
  • Visitor pattern: A way to separate an algorithm from an object
Weblogic Domain and Cluster


What is a domain?

A domain, in weblogic world, is a set of weblogic (WL) instances that can be managed by the same administration console.
That’s why they are call managed servers.
Each WL instance can run on the same machine of the administration server or remotely

What is a weblogic instance?

It is just an ip and port address where the single weblogic listen

Why to use (or at least to be aware)

If you have different weblogic servers that you need to manage (remotely for example) you can create a domain that includes them.
Or/And, if you need a cluster of instances then you must before add all cluster instances in a domain and then you can create your cluster
So you can have two types on WL instances in a domain: Standalone (which don’t belong to any cluster) and Clustered

How

In weblogic console, in Environment==> Servers you can add you weblogic instances. You have just to know the ip and port address of each weblogic instance you want to add in the domain

What is a cluster?

A cluster is a subset of a weblogic domain, where each WL instance of the cluster has the same goal: allow load balancing and fail over for the fantastic (same) applications they host.

Of course, as you manage a set of instance for the same application(s), when you deploy the application you do it just one time for all WL instance in the cluser, and the WebLogic Administration is in charge of update all instances in the cluster.
Just a thing good to know: all the WL in a cluster must have the same WL version

From a client point of view the cluster is transparent. The client doesn’t know how many WL instances there are behind that ip address

Why

Advantages of a cluster are the same of LoadBalancing and Failover.

Scalability (Load Balancing): The capacity of an application deployed on a WebLogic Server cluster can be increased dynamically to meet demand. You can add server instances to a cluster without interruption of service, the application continues to run without impact to clients and end users.


High-Availability (Failover): In a WebLogic Server cluster, application processing can continue when a server instance fails. You “cluster” application components by deploying them on multiple server instances in the cluster so, if a server instance on which a component is running fails, an other server instance on which that component is deployed can continue application processing.

How

You can manage WL instances for a cluster in just two steps:

  1. create the cluster (in Environment ==> clusters ==> new button)
  2. for each existing or new server you can choose a cluster

That’s it!

Debug remotely with Eclipse

To debug with eclipse to remote server follow below instructions

In the menu Run –> Debug configurations…

In the window popup select Remote Java Application

Right click, then select New

On the right a new fieldset appears

In the Project field browse the java project to attach

In the Connection Type field:

  • Select “Standard (Socket Attach)” – int the 99% of cases -, if you want to attach your eclipse to a server (which listen on a ip and port). In this case you should specify the IP/name and the port of the server you want to attach
  • Select “Standard (Socket Listen)”, if you want to be the host, listening just on a port (and on your ip). In this case you should just specify the port and the connection number you want to allow. Of course the machine is the same of eclispe running instance

The listening port, in both case (local and remote), must be preconfigured setting, as jvm parameters, the following:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4000

  • The -XDebug parameter enables debugging
  • The -Xrunjdwp parameter loads the JPDA reference implementation of JDWP
  • Debugging, in the example, is enabled on port 4000

The JDWP protocol is the protocol used to debug with a remote debugger.

For example, in WebLogic server, to allow a debug socket listener, in the file “startWebLogic.cmd” add to the JAVA OPTIONS:

set JAVA_OPTIONS=-<others params> Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n

The -Xnoagent parameter disables the default sun.tools.debug debug agent

Just a little notice: if you want to debug clustered application, you have to attach the debug ide to all clustered servers, otherwise you need to be lucky to get the request to your debugged server

Curiosity: default debug port on weblogic 12.1.3 is 8453

Label in Java

The label in Java (from version 7) is a way of giving a logic name to a loop statement.

Why naming a statement in Java?
Just because in case, of very deeper loops, you want to break/continue that specific statement.

How to give a name to a statement?
Specifying a name (as a class style) followed by “:”

How can you break using label?
Simple, with break and continue followed by the label name. That’s it.

Example

  Task:
  {
    (loop statement){
        if (condition){
            break Task;
        }
    }
  }

In the above example “Task” is the label. When you reach the line “break Task;” the program will go outside the Task statement.
Of course the similar logic works with “continue Task;“, but in this case the program will continue with labeled statement.

A little curiosity, the below code works perfectly:

public int myMethod(){
http://www.google.com
return 1;
}

because “http:” is treated as label and “//www.google.com” is treated as comment