JCA 1.6 connectorZ

Java Connector Architecture (JCA) 1.6 connectors. As Simple as Possible.

Work Manager:

  1. A JCA 1.6 compliant Executor implementation
  2. 2 API classes
  3. 5 Implementation classes
  4. No XML deployment descriptors
  5. Maven 3 Build
  6. Sample use:
    
    @Stateless
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public class ThreadsResource {
    
        @Resource(name="jca/workmanager")
        WorkExecutorFactory executorFactory;
        
        public String threads(){
            try(WorkExecutor executor = executorFactory.newExecutor();){
            Runnable runnable = new Runnable(){
                @Override
                public void run() {
                //some work to do
                }
            };
            executor.execute(runnable);
      }
                            

Transactional File Access:

  1. A JCA 1.6 compliant File IO implementation
  2. 2 API classes
  3. 5 Implementation classes
  4. No XML deployment descriptors
  5. Maven 3 Build
  6. Sample use:
                    
                    
    
        import java.net.URI;
        import javax.annotation.Resource;
        import javax.ejb.Stateless;
        import javax.ws.rs.*;
        import javax.ws.rs.core.MediaType;
        import javax.ws.rs.core.Response;
        import org.connectorz.files.Bucket;
        import org.connectorz.files.BucketStore;
    
        @Path("files")
        @Stateless
        @Consumes(MediaType.TEXT_PLAIN)
        @Produces(MediaType.TEXT_PLAIN)
        public class FilesResource {
    
            @Resource(name = "jca/files")
            BucketStore bucketStore;
    
            @PUT
            @Path("{id}")
            public Response put(@PathParam("id") String id, String content) {
                try (Bucket bucket = bucketStore.getBucket();) {
                    bucket.write(id, content.getBytes());
                }
                URI createdURI = URI.create(id);
                return Response.created(createdURI).build();
            }
    
            @GET
            @Path("{id}")
            public String fetch(@PathParam("id") String id) {
                try (Bucket bucket = bucketStore.getBucket();) {
                    final byte[] content = bucket.fetch(id);
                    if(content == null)
                        return null;
                    return new String(content);
                }
            }
    
            @DELETE
            @Path("{id}")
            public void delete(@PathParam("id") String id) {
                try (Bucket bucket = bucketStore.getBucket();) {
                    bucket.delete(id);
                }
            }
        }
    
                    

This connector is also documented in the book Real World Java EE (6) Patterns--Rethinking Best Practices, chapter "Generic (File) JCA", page 303

Sources: https://github.com/AdamBien/connectorz