Skip to content

Instantly share code, notes, and snippets.

Avatar

Carl Harris ceharris

  • Blacksburg, VA, USA
View GitHub Profile
@ceharris
ceharris / collections.md
Last active Nov 23, 2016
prospecto collection syntax improvement
View collections.md

This is the current syntax...

mapOfObjects(Role.class, Contributor.class)
    .reference("person", PERSON_SUMMARY_TEMPLATE)
    .arrayOfObjects("credits")
          .reference("responsibleOrganization", ORG_SUMMARY_TEMPLATE)
          .value("percentCredit")
          .end()
View gist:25dddcb7049ec8ebf5be31d2c27a9f10
Verifying that "ceharris.id" is my Blockstack ID. https://onename.com/ceharris
View keybase.md

Keybase proof

I hereby claim:

  • I am ceharris on github.
  • I am ceharris (https://keybase.io/ceharris) on keybase.
  • I have a public key whose fingerprint is 5CD3 C1D5 CD3D AC5C 1040 75CC DF48 BD89 3F1F 38CE

To claim this, I am signing this object:

@ceharris
ceharris / jax-rs-web.xml
Created Oct 16, 2014
JAX-RS Application Servlet Mapping
View jax-rs-web.xml
<!-- This gist simply provides the web.xml configuration needed to support JAX-RS endpoints -->
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/api/*</url-pattern>
@ceharris
ceharris / SOAPRewriteDemo.java
Last active Dec 21, 2015
Using Java with JDOM to write a SOAP header. Either finds and replaces or adds a SOAP header containing a session ID.
View SOAPRewriteDemo.java
package demo;
import java.io.InputStream;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
View AbstractSocketAppender.java
class AbstractSocketAppender extends ...
implements EventDispatcher, ExceptionHandler {
private SocketConnectorFactory connectorFactory;
private ConnectionRunner connectionRunner;
private Future<?> runnerTask;
public void start() {
...
// extract method to create connector factory...
@ceharris
ceharris / README.md
Last active Dec 16, 2015
An example of the (non-)effect of Thread.interrupt on a fairly typical long-running task.
View README.md

I think that Thread.interrupt() sounds more intrusive than it really is. Thread interruption in Java is entirely advisory. Generally a task does not need to go to any effort to avoid being interrupted. Rather, it usually takes some real effort to properly observe the interrupt status in order to exit when interrupted, if such is desired. Short of putting in the effort to observe the thread's interrupt status, I think you'll find that arbitrary tasks are quite resilient in the face of interrupts.

A task can check the thread's interrupt status at any time by calling Thread.isInterrupted(). If you wish to make a runnable task interruptible, your code must occasionally check the interrupt status and exit the run() method if the task has been interrupted. If you don't want your task to be interrupted, simply ignore the thread's interrupt status.

JDK methods that examine the thread's interrupt status are consistently declared to throw InterruptedException, so they are easily identified. I/O calls w