public Cloud(int id, Channel leftIn, Channel leftOut,
			Channel rightIn, Channel rightOut) {
		this.id_ = id;
		this.leftIn_ = leftIn;
		this.leftOut_ = leftOut;
		this.rightIn_ = rightIn;
		this.rightOut_ = rightOut;
		name = this.getId();
		currentState = Status.PRE_AUTHED;
		
		/* Swing parts */
		cloudLbl = new JLabel("Cloud"+id);
		cloudBtn = new JButton("Waiting");
		cloudBtn.setEnabled(false);
		
		add(cloudLbl);
		add(cloudBtn);
		
		cloudLbl.setAlignmentX(Component.CENTER_ALIGNMENT);	
		cloudBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		
		
		/* Pane Config */
		setPreferredSize(Config.ENTITY_SIZE);
		setLayout(new GridLayout(3,1 ));
		//setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		setBorder(BorderFactory.createMatteBorder(1, 2, 1, 1,Color.black));
		
		
		cloudBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					switch (currentState) {
					
					/* The Java implementation keeps track of "happens-before" events
					 * in order to execute the correct sequence of events according to specific input events
					 */
					
					/* We have to send a GETPIN request to verify the user in the PRE_AUTHED State */
					case PRE_AUTHED:
						ThreadHelper.threadMessage("Send GETPIN to DB", getId());
						Message authMsg = new Message(Message.Type.GETPIN, servedUser, id_);
						//ThreadHelper.threadMessage("Requesting PIN from DB", name);
						//ThreadHelper.threadMessage("Sending PIN Request over network", name);
						lastMsgSentOnRight_ = authMsg; 
						rightOut_.send(authMsg);
						cloudBtn.setEnabled(false);
						break;
						
					/* We can send a AUTHOK to the ATM after being AUTHED */	
					case AUTHED:
						ThreadHelper.threadMessage("Send AUTHOK to ATM"+id_, getId());
						Message authOKMsg = new Message(Message.Type.AUTHOK, servedUser, id_);	
						lastMsgSentOnLeft_ = authOKMsg;
						leftOut_.send(authOKMsg);
						cloudBtn.setEnabled(false);
						break;
					
					/* 	We can Send a DEAUTHOK message back to the ATM after handling a CANCEL request */
					case CANCELED:
						ThreadHelper.threadMessage("Send DEAUTHOK to ATM"+getId(), getId());
						Message deauthOKMsg = new Message(Message.Type.DEAUTHOK, servedUser, id_);
						lastMsgSentOnLeft_ = deauthOKMsg;
						leftOut_.send(deauthOKMsg);
						cloudBtn.setEnabled(false);
						break;
						
					/* We have to RETRIEVERECORD from the Database before actually WITHDRAWING */	
					case PRE_WITHDRAW:
						ThreadHelper.threadMessage("Send GETBALANCE("+servedUser+") to DB", getId());
						Message recMsg = new Message(Message.Type.GETBALANCE, servedUser, id_);	
						lastMsgSentOnRight_ = recMsg;
						rightOut_.send(recMsg);
						cloudBtn.setEnabled(false);
						break;
						
					/* We can send a SETBALANCE request upon receiving a record */	
					case RECORDFETCHED:
						ThreadHelper.threadMessage("Send SETBALANCE("+servedUser+") to DB", getId());
						lastMsgSentOnRight_ = new Message(Message.Type.SETBALANCE, servedUser, id_);
						rightOut_.send(lastMsgSentOnRight_); // relay		
						cloudBtn.setEnabled(false);
						break;

					/* We can send a WITHDRAWOK to the ATM after a successful SETBALANCE */	
					case WITHDRAWN:		
						ThreadHelper.threadMessage("Send WITHDRAWOK to ATM"+id_, getId());
						lastMsgSentOnLeft_ = new Message(Message.Type.WITHDRAWOK, servedUser, id_);
						leftOut_.send(lastMsgSentOnLeft_); // relay	
						cloudBtn.setEnabled(false);
						break;
						
					/* A FAILURE message from the channel between ATM-Cloud is dealt with by a resend */	
					case FAILUREFROMLEFT:
						ThreadHelper.threadMessage("Resend "+lastMsgSentOnLeft_+" to ATM"+getId(), getId());
						leftOut_.send(lastMsgSentOnLeft_);
						cloudBtn.setEnabled(false);
						break;
						
						
					/* A FAILURE message from the channel between Cloud-DB is dealt with by a resend */		
					case FAILUREFROMRIGHT:
						ThreadHelper.threadMessage("Resend "+lastMsgSentOnRight_+" to DB"+getId(), getId());
						rightOut_.send(lastMsgSentOnRight_);
						cloudBtn.setEnabled(false);
						break;
					}
				} catch(Exception ie){}
			}
		});
		
	}