Showing posts from 2020

Java Conversion Types and Conversion Contexts

When an expression evaluated in Java programing language it either produce a result or nothing. An expression denotes nothing if and only if it is a method invocation. An expression produce a result has a type that can be deduced at compile time from the structure of the expression, the types of the literals, variables, and methods mentioned in the expression. The expression that produce a result will always evaluated in some context and it must be compatible with a type expected in that context; this type is called the target type. The compatibility of expression with it's surrounding context type is determined as  The expression the deduced type can be influenced by the target type After the type of the expression has been deduced, an implicit conversion from the type of the expression to the target type can be performed If neither of the above strategy is able to produce the appropriate type, a compile-time error occurs. In some cases context is able to accept a expression type

Puzzle: The throws clause on a constructor declaration

Although it is common to see a throws clause on a method declaration, it is less common to see one on a constructor declaration. The following program has such a declaration. What does it print? public class Test { private Test instance = new Test() ; public Test () throws Exception { throw new Exception( "Runtime Exception" ) ; } public static void main (String[] args) { try { Test b = new Test() ; System. out .println( "Surprise!" ) ; } catch (Exception ex) { System. out .println( "Exception throw by constructor" ) ; } } } The main method invokes the constructor of Test class, which throws an exception. You might expect the catch clause to catch this exception and print "Exception throw by constructor". But if you tried running it, you found that it does not print anything : It throws a StackOverflowError . Why? if you have a closer look at the program the

Continuous Integration with Jenkins

Continuous integration Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies to a shared mainline several times a day. It was first named and proposed by Grady Booch in his 1991. although Booch did not advocate integrating several times a day. The main aim of CI is to prevent integration problems, referred to as "integration hell" in early descriptions of XP. CI isn't universally accepted as an improvement over frequent integration, so it is important to distinguish between the two as there is disagreement about the virtues of each. In XP, CI was intended to be used in combination with automated unit tests written through the practices of test-driven development. Continuous integration (CI) is an integral part of an agile software development setup. Sprint after sprint, teams strive to "not break the build" while delivering incremental features. But when developers focus completely on adding features, code

Load Balancing usign HAProxy for Openfire

Introduction HAProxy, which stands for High Availability Proxy, is a popular open source software TCP/HTTP Load Balancer and proxying solution. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g. web, application, database). Installing HAProxy $ apt-get install haproxy We need to enable HAProxy to be started by the init script. $ nano /etc/default/haproxy Set the ENABLED option to 1 ENABLED=1 Configuring HAProxy HAProxy's configuration process involves 3 major sources of parameters the arguments from the command-line, which always take precedence the "global" section, which sets process-wide parameters the proxies sections which can further divide as defaults listen frontend backend The configuration file syntax consists in lines beginning with a keyword referenced in this manual, optionally followed by one or several parameters delimited by spaces. 1

Enable Clustering in Openfire

Clustering Clustering is a technique used to "scale up" a single XMPP domain. The server members within a cluster share an identical configuration. Each member allows any user within the domain to connect, authenticate, and exchange stanzas. Clustered server shares a single database, and also required to be resident within the same LAN-based (low latency) network infrastructure. This type of deployment is suitable to provide runtime redundancy and will support a larger number of users and connections (within a single domain) than a single server. How to Cluster Openfire To create an Openfire cluster, you should have at least two Openfire servers, and each server must have the Hazelcast plugin installed. Install hazelcast plugin The Hazelcast plugin version corresponding to the Openfire release (3.9.3) is 1.2.0 Edit the config file of hazelcast in plugins/hazelcast/classes directory $nano openfire/plugins/hazelcast/classes/hazelcast-cache-config.xml By de

Enable JMX Port in Tomcat with authentication

What is JMX ? Java provides a technology called JMX that supplies tools for monitoring and managing applications, system objects, devices and service-oriented networks. Those resources are represented by objects called Managed Bean (MBeans) Enable JMX port in Tomcat To monitor Heap Memory, Threads, CPU Usage, Classes, and configure various MBeans at remote we need to enable a JMX port in tomcat. Step 1: Go to path where you have Tomcat installed $ cd /usr/share/tomcat7/bin Step 2: Make file and give it the read, execute and access permission $ chmod 755 Step 3: Edit the setenv .sh file and paste the following lines export JAVA_OPTS=" \\\ \ -Djava.rmi.server.hostname=192.168.x.x"   1. enables jmxremote   2 . specifies the port  3. says that we don’t need to use ssl  4. says to leave

Tomcat SSL/TLS Configuration | Run tomcat over HTTPS

HTTPS HTTPS (also called HTTP over TLS, HTTP over SSL and HTTP Secure) is a protocol for secure communication over a computer network which is widely used on the Internet. HTTPS consists of communication over Hypertext Transfer Protocol (HTTP) within a connection encrypted by Transport Layer Security or its predecessor, Secure Sockets Layer. The main motivation for HTTPS is authentication of the visited website and protection of the privacy and integrity of the exchanged data. SSL SSL (Secure Sockets Layer) is the standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral. SSL is a security protocol. Protocols describe how algorithms should be used. TLS Transport Layer Security (TLS) and its predecessor, Secure Sockets Layer (SSL), both of which are frequently referred to as 'SSL', are cryptographic protocols designed to provide communi

PubNub Access Manager

Pubnub Access Manager PubNub Access Manager (PAM) extends PubNub's existing security framework by allowing developers to create and enforce secure access to channels throughout the PubNub Real Time Network. Access Manager allows you to manage granular permissions for your realtime apps and data streams, create multiple permission levels, grant and revoke access, and audit user access. To use Access Manager, you need to enable Access Manager in the Admin Dashboard. Once you enable Access Manager, you must grant permissions before any data can be sent or received. PAM Server side Configuration In order to client side working correctly, at server side must first issue the appropriate permissions for a given PAM channel or channel-group and auth token combination. for granting these permission you must initialize pubnub instance at least with your subscribe and secret keys. Example : Step 1. Make Pubnub Configuration : - PNConfiguration pnConfiguration = new PNConfigurat

PubNub Webhook Overview

Webhook Overview A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. A web application implementing WebHooks will POST a message to a URL when certain things happen. PubNub Presence Pubnub presence all about the user presence at pubnub platform. it provides the presence of user when they are joining, leaving a channel or when there is a user's state changes. Presence Webhooks provide a means for your server to be notified whenever presence events occur on any channel for your keys. This provides an easy to scale solution for your server side application to monitor the presence events. How it would reduce the overhead Without Presence Webhooks, your server would have to subscribe to all the channels'  -pnpres channels. So this can be a tedious task to control overs channels if your app has thousands of channels or more. Pubnub Webhooks would help us in this scenario and it is easier to implement and sc

Character Set in Java

A character set refers to the composite number of different characters that are being used and supported by a computer software and hardware. Almost all computer systems and languages use the ASCII character encoding. The ASCII code represents each character using 8 bits (that is, one byte) and there are 256 different characters available. Several of these are "control characters." Java, however, uses 16 bits (that is, 2 bytes) for each character and uses an encoding called Unicode. The first 256 characters in the Unicode character set correspond to the traditional ASCII character set, but the Unicode character set also includes many unusual characters and symbols from several different languages. Typically, a new Java program is written and placed in a standard ASCII file. Each byte is converted into the corresponding Unicode character by the Java compiler as it is read in. When an executing Java program reads (or writes) character data, the characters are tr