polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [6/7] zest-java git commit: ZEST-181 : Replaced the use of 'long' as a time and using java.time.Instant instead.
Date Sat, 22 Oct 2016 07:18:51 GMT
http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java
----------------------------------------------------------------------
diff --git a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java
b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java
index 39ad21a..9d1258b 100644
--- a/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java
+++ b/libraries/logging/src/main/java/org/apache/zest/library/logging/trace/service/TraceServiceMixin.java
@@ -21,6 +21,8 @@
 package org.apache.zest.library.logging.trace.service;
 
 import java.lang.reflect.Method;
+import java.time.Duration;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.zest.api.ZestAPI;
@@ -67,14 +69,14 @@ public class TraceServiceMixin
                               Method method,
                               Object[] args,
                               Object result,
-                              long entryTime,
-                              long durationNano
+                              Instant entryTime,
+                              Duration duration
     )
     {
         UnitOfWork uow = uowf.newUnitOfWork();
         try
         {
-            createTraceRecord( uow, compositeType, object, method, args, entryTime, durationNano,
null );
+            createTraceRecord( uow, compositeType, object, method, args, entryTime, duration,
null );
             uow.complete();
         }
         catch( ConcurrentEntityModificationException e )
@@ -93,14 +95,14 @@ public class TraceServiceMixin
                                 Method method,
                                 Object[] args,
                                 Throwable t,
-                                long entryTime,
-                                long durationNano
+                                Instant entryTime,
+                                Duration duration
     )
     {
         UnitOfWork uow = uowf.newUnitOfWork();
         try
         {
-            createTraceRecord( uow, compositeType, object, method, args, entryTime, durationNano,
t );
+            createTraceRecord( uow, compositeType, object, method, args, entryTime, duration,
t );
             uow.complete();
         }
         catch( ConcurrentEntityModificationException e )
@@ -118,8 +120,8 @@ public class TraceServiceMixin
                                     Composite object,
                                     Method method,
                                     Object[] args,
-                                    long entryTime,
-                                    long durationNano,
+                                    Instant entryTime,
+                                    Duration duration,
                                     Throwable exception
     )
     {
@@ -134,7 +136,7 @@ public class TraceServiceMixin
                     .orElse( null ), identity );
             EntityBuilder<EntityTraceRecordEntity> builder = uow.newEntityBuilder(
EntityTraceRecordEntity.class );
             EntityTraceRecordEntity state = builder.instance();
-            setStandardStuff( compositeType, method, args, entryTime, durationNano, state,
exception );
+            setStandardStuff( compositeType, method, args, entryTime, duration, state, exception
);
             state.source().set( source );
             EntityTraceRecordEntity etr = builder.newInstance();  // Record is created.
         }
@@ -143,7 +145,7 @@ public class TraceServiceMixin
             ServiceComposite service = (ServiceComposite) object;
             EntityBuilder<ServiceTraceRecordEntity> builder = uow.newEntityBuilder(
ServiceTraceRecordEntity.class );
             ServiceTraceRecordEntity state = builder.instance();
-            setStandardStuff( compositeType, method, args, entryTime, durationNano, state,
exception );
+            setStandardStuff( compositeType, method, args, entryTime, duration, state, exception
);
             state.source().set( service.toString() );
             ServiceTraceRecordEntity str = builder.newInstance();  // Record is created.
         }
@@ -152,7 +154,7 @@ public class TraceServiceMixin
             EntityBuilder<CompositeTraceRecordEntity> builder = uow.newEntityBuilder(
CompositeTraceRecordEntity.class );
             CompositeTraceRecordEntity state = builder.instance();
             state.source().set( object );
-            setStandardStuff( compositeType, method, args, entryTime, durationNano, state,
exception );
+            setStandardStuff( compositeType, method, args, entryTime, duration, state, exception
);
             CompositeTraceRecordEntity ctr = builder.newInstance();  // Record is created.
         }
     }
@@ -160,13 +162,13 @@ public class TraceServiceMixin
     private void setStandardStuff( Class compositeType,
                                    Method method,
                                    Object[] args,
-                                   long entryTime,
-                                   long durationNano,
+                                   Instant entryTime,
+                                   Duration duration,
                                    TraceRecord state,
                                    Throwable exception
     )
     {
-        state.duration().set( durationNano );
+        state.duration().set( duration );
         state.entryTime().set( entryTime );
         state.methodName().set( method.getName() );
         state.compositeTypeName().set( compositeType.getName() );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java
----------------------------------------------------------------------
diff --git a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java
b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java
index a172171..5947683 100755
--- a/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java
+++ b/libraries/rdf/src/test/java/org/apache/zest/library/rdf/entity/EntitySerializerTest.java
@@ -21,6 +21,8 @@
 package org.apache.zest.library.rdf.entity;
 
 import java.io.PrintWriter;
+import java.time.Instant;
+import org.apache.zest.api.time.SystemTime;
 import org.junit.Before;
 import org.junit.Test;
 import org.openrdf.model.Statement;
@@ -83,7 +85,7 @@ public class EntitySerializerTest
     {
         EntityReference entityReference = new EntityReference( "test2" );
         Usecase usecase = UsecaseBuilder.newUsecase( "Test" );
-        long currentTime = System.currentTimeMillis();
+        Instant currentTime = SystemTime.now();
         EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( module, usecase, currentTime
);
         EntityState entityState = unitOfWork.entityStateOf( module, entityReference );
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java
b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java
index e92338b..d8d43e0 100644
--- a/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java
+++ b/libraries/rest-server/src/main/java/org/apache/zest/library/rest/server/api/ResourceValidity.java
@@ -21,6 +21,7 @@
 package org.apache.zest.library.rest.server.api;
 
 import java.time.Instant;
+import java.time.temporal.ChronoField;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.unitofwork.NoSuchEntityException;
 import org.apache.zest.api.unitofwork.UnitOfWork;
@@ -67,7 +68,7 @@ class ResourceValidity
         {
             EntityState state = spi.entityStateOf( entity );
             Tag tag = new Tag( state.identity().identity() + "/" + state.version() );
-            response.getEntity().setModificationDate( new java.util.Date( state.lastModified()
) );
+            response.getEntity().setModificationDate( java.util.Date.from( state.lastModified()
) );
             response.getEntity().setTag( tag );
         }
     }
@@ -78,10 +79,10 @@ class ResourceValidity
         // Check command rules
         Instant unmodifiedSince = request.getConditions().getUnmodifiedSince().toInstant();
         EntityState state = spi.entityStateOf( entity );
-        Instant lastModified = cutoffMillis( state.lastModified() );
+        Instant lastModifiedSeconds = state.lastModified().with(ChronoField.NANO_OF_SECOND,
0 );
         if( unmodifiedSince != null )
         {
-            if( lastModified.isAfter( unmodifiedSince ) )
+            if( lastModifiedSeconds.isAfter( unmodifiedSince ) )
             {
                 throw new ResourceException( Status.CLIENT_ERROR_CONFLICT );
             }
@@ -91,15 +92,10 @@ class ResourceValidity
         Instant modifiedSince = request.getConditions().getModifiedSince().toInstant();
         if( modifiedSince != null )
         {
-            if( !lastModified.isAfter( modifiedSince ) )
+            if( !lastModifiedSeconds.isAfter( modifiedSince ) )
             {
                 throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
             }
         }
     }
-
-    private Instant cutoffMillis( long time )
-    {
-        return Instant.ofEpochMilli( time / 1000 * 1000 );
-    }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java
----------------------------------------------------------------------
diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java
b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java
index cff150b..212678c 100755
--- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java
+++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/EntityResource.java
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.Writer;
-import java.time.Instant;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -37,6 +36,7 @@ import org.apache.zest.api.injection.scope.Service;
 import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.injection.scope.Uses;
 import org.apache.zest.api.structure.ModuleDescriptor;
+import org.apache.zest.api.time.SystemTime;
 import org.apache.zest.api.usecase.Usecase;
 import org.apache.zest.api.usecase.UsecaseBuilder;
 import org.apache.zest.api.value.ValueSerialization;
@@ -69,8 +69,6 @@ import org.restlet.representation.WriterRepresentation;
 import org.restlet.resource.ResourceException;
 import org.restlet.resource.ServerResource;
 
-import static java.time.Instant.ofEpochMilli;
-
 public class EntityResource
     extends ServerResource
 {
@@ -114,7 +112,7 @@ public class EntityResource
         throws ResourceException
     {
         Usecase usecase = UsecaseBuilder.newUsecase( "Remove entity" );
-        EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, System.currentTimeMillis()
);
+        EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, usecase, SystemTime.now()
);
         try
         {
             EntityReference identityRef = EntityReference.parseEntityReference( identity
);
@@ -136,7 +134,7 @@ public class EntityResource
         throws ResourceException
     {
         EntityStoreUnitOfWork uow = entityStore.newUnitOfWork( module, UsecaseBuilder.newUsecase(
"Get entity" ),
-                                                               System.currentTimeMillis()
);
+                                                               SystemTime.now() );
 
         try
         {
@@ -146,7 +144,7 @@ public class EntityResource
             java.util.Date lastModified = getRequest().getConditions().getModifiedSince();
             if( lastModified != null )
             {
-                if( lastModified.toInstant().getEpochSecond() == ofEpochMilli( entityState.lastModified()).getEpochSecond()
)
+                if( lastModified.toInstant().getEpochSecond() == entityState.lastModified().getEpochSecond()
)
                 {
                     throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
                 }
@@ -193,7 +191,7 @@ public class EntityResource
 
     private Representation entityHeaders( Representation representation, EntityState entityState
)
     {
-        representation.setModificationDate( new java.util.Date( entityState.lastModified()
) );
+        representation.setModificationDate( java.util.Date.from( entityState.lastModified()
) );
         representation.setTag( new Tag( "" + entityState.version() ) );
         representation.setCharacterSet( CharacterSet.UTF_8 );
         representation.setLanguages( Collections.singletonList( Language.ENGLISH ) );
@@ -355,7 +353,7 @@ public class EntityResource
         throws ResourceException
     {
         Usecase usecase = UsecaseBuilder.newUsecase( "Update entity" );
-        EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( module, usecase, System.currentTimeMillis()
);
+        EntityStoreUnitOfWork unitOfWork = entityStore.newUnitOfWork( module, usecase, SystemTime.now()
);
         EntityState entity = getEntityState( unitOfWork );
 
         Form form = new Form( entityRepresentation );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/samples/forum/src/main/java/org/apache/zest/sample/forum/context/view/ViewPost.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/context/view/ViewPost.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/context/view/ViewPost.java
index 7480607..f98c503 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/context/view/ViewPost.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/context/view/ViewPost.java
@@ -70,7 +70,7 @@ class ViewPost
             Post post = uowf.currentUnitOfWork().newEntity( Post.class );
             post.message().set( message );
             post.createdBy().set( poster.self() );
-            post.createdOn().set( Instant.ofEpochMilli( uowf.currentUnitOfWork().currentTime())
);
+            post.createdOn().set( uowf.currentUnitOfWork().currentTime() );
             post.replyTo().set( viewPost.self() );
 
             self().lastPost().set( post );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEventValue.java
----------------------------------------------------------------------
diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEventValue.java
b/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEventValue.java
index 71a08c5..487f686 100644
--- a/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEventValue.java
+++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/domainevent/DomainEventValue.java
@@ -19,6 +19,7 @@
  */
 package org.apache.zest.sample.forum.domainevent;
 
+import java.time.Instant;
 import java.util.List;
 import org.apache.zest.api.common.UseDefaults;
 import org.apache.zest.api.property.Property;
@@ -34,7 +35,7 @@ public interface DomainEventValue
     Property<String> version();
 
     // When the event occurred
-    Property<Long> timestamp();
+    Property<Instant> timestamp();
 
     // Selected objects
     @UseDefaults

http://git-wip-us.apache.org/repos/asf/zest-java/blob/e030bd8a/tests/performance/src/perf/java/org/apache/zest/test/performance/runtime/composite/CompositeCreationPerformanceTest.java
----------------------------------------------------------------------
diff --git a/tests/performance/src/perf/java/org/apache/zest/test/performance/runtime/composite/CompositeCreationPerformanceTest.java
b/tests/performance/src/perf/java/org/apache/zest/test/performance/runtime/composite/CompositeCreationPerformanceTest.java
index da2b947..ad6c93a 100644
--- a/tests/performance/src/perf/java/org/apache/zest/test/performance/runtime/composite/CompositeCreationPerformanceTest.java
+++ b/tests/performance/src/perf/java/org/apache/zest/test/performance/runtime/composite/CompositeCreationPerformanceTest.java
@@ -17,6 +17,9 @@
  */
 package org.apache.zest.test.performance.runtime.composite;
 
+import java.time.Duration;
+import java.time.Instant;
+import org.apache.zest.api.time.SystemTime;
 import org.junit.Test;
 import org.apache.zest.api.activation.ActivationException;
 import org.apache.zest.api.composite.TransientBuilder;


Mime
View raw message