Skip to content

Instantly share code, notes, and snippets.

View karanmalhi's full-sized avatar

Karan Singh Malhi karanmalhi

  • MuleSoft
  • San Francisco
View GitHub Profile
@karanmalhi
karanmalhi / Debugger.java
Created July 28, 2011 19:37
ThreadLocal example
import java.util.ArrayList;
import java.util.List;
public class Debugger {
public static void main(String[] args) {
ThreadGroup cleanupThreads = new ThreadGroup("Cleanup group");
Thread t1 = new Thread(cleanupThreads, new Printer());
Thread t2 = new Thread(cleanupThreads, new Printer());
t1.start();
t2.start();
@karanmalhi
karanmalhi / Test.java
Created July 28, 2011 21:25
Challenge to invoke methods using reflection and annotation processing
package learnquest;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.Date;
@karanmalhi
karanmalhi / ProxyCreator.java
Created August 17, 2011 17:23
Creating a proxy with JavAssist
package mit.proxy;
import java.lang.reflect.Method;
import java.util.ArrayList;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;
public class ProxyCreator {
@karanmalhi
karanmalhi / gist:1230754
Created September 20, 2011 23:45
Can't assign requeted address
SEVERE: Error starting endpoint
java.net.BindException: Can't assign requested address /172.16.10.170:60001
at org.apache.tomcat.util.net.JIoEndpoint.init(JIoEndpoint.java:549)
at org.apache.tomcat.util.net.JIoEndpoint.start(JIoEndpoint.java:565)
at org.apache.coyote.http11.Http11Protocol.start(Http11Protocol.java:203)
at org.apache.catalina.connector.Connector.start(Connector.java:1095)
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:277)
at com.mulesoft.tcat.agent.web.AgentServlet.doCreateSecureConnector(AgentServlet.java:225)
at com.mulesoft.common.agent.servlet.AbstractAgentServlet.createSecureConnector(AbstractAgentServlet.java:245)
at com.mulesoft.common.agent.servlet.AbstractAgentServlet.pair(AbstractAgentServlet.java:129)
@karanmalhi
karanmalhi / worker.properties
Created December 6, 2011 21:18
Used to configure workers
#The list of workers
worker.list=balancer,stats
#The template contains default values. Each worker will inherit
#these values and override the port
# the worker type
worker.template.type=ajp13
#This could also be an IP address. Since all Tomcat instances
#and IIS are installed on the same host, hence "localhost"
@karanmalhi
karanmalhi / uriworkermap.properties
Created December 6, 2011 21:21
uriworkermap.properties to map URL Path patterns to workers
#/foo and /foo/* are both mapped to balancer worker
/foo|/*=balancer
#/jkstatus is mapped to the stats worker
/jkstatus/=stats
@karanmalhi
karanmalhi / isapi_redirect.properties
Created December 6, 2011 21:24
The properties file which ties everything together.
#tomcat will be the name of the virtual directory under IIS
extension_uri=/tomcat/isapi_redirect.dll
#location of the log file
log_file=C:\inetpub\isapi\logs\isapi_redirect.log
log_level=debug
#location of worker.properties
worker_file=C:\inetpub\isapi\conf\worker.properties
#location of uriworkermap.properties
worker_mount_file=C:\inetpub\isapi\conf\uriworkermap.properties
@karanmalhi
karanmalhi / index.jsp
Created December 6, 2011 22:04
A simple index.jsp file which shows some session information
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Apache Tomcat Examples</TITLE>
<META http-equiv=Content-Type content="text/html">
</HEAD>
<BODY>
<h3>Session ID = <%=session.getId()%></h3>
<h3>Creation Time = <%=session.getCreationTime()%></h3>
</BODY></HTML>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<distributable/>
@karanmalhi
karanmalhi / gist:2765027
Created May 21, 2012 22:15
deploymentStatus
private DeploymentStatus getDeploymentStatus(DeploymentAction latest) {
DeploymentStatus status;
if (Action.DELETE.equals(latest.getAction())) {
status = DeploymentStatus.DELETING;
} else {
boolean inProcess = false;
int failCount = 0;
// if size is 0, that means we do not have any status yes, a typical indication that the deployment on servers has not started yet.
if (latest.getStatuses().size() == 0) {
// the deployment is still in progress, i.e. about to start