= MetricsService
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Hooks into the transaction nechanism to provide a counters relating to numbers of object loaded, dirtied etc.

Only entities with _DomainObject#entityChangePublishing()_ enabled are counted.

== API

[source,java]
.MetricsService.java
----
interface MetricsService {
  int numberEntitiesLoaded()     // <.>
  int numberEntitiesDirtied()     // <.>
}
----

<.> xref:#numberEntitiesLoaded_[numberEntitiesLoaded()]
+
--
The number of entities that have, so far in this request, been loaded from the database.
--
<.> xref:#numberEntitiesDirtied_[numberEntitiesDirtied()]
+
--
The number of objects that have, so far in this request, been dirtied/will need updating in the database); a good measure of the footprint of the interaction.
--

== Members

[#numberEntitiesLoaded_]
=== numberEntitiesLoaded()

The number of entities that have, so far in this request, been loaded from the database.

Corresponds to the number of times that `javax.jdo.listener.LoadLifecycleListener#postLoad(InstanceLifecycleEvent)` (or equivalent) is fired.

Is captured within _MemberExecutionDto#getMetrics()_ (accessible from _InteractionProvider#currentInteraction()_ ).

[#numberEntitiesDirtied_]
=== numberEntitiesDirtied()

The number of objects that have, so far in this request, been dirtied/will need updating in the database); a good measure of the footprint of the interaction.

Corresponds to the number of times that `javax.jdo.listener.DirtyLifecycleListener#preDirty(InstanceLifecycleEvent)` (or equivalent) callback is fired.

Is captured within _MemberExecutionDto#getMetrics()_ (accessible from _InteractionProvider#currentInteraction()_ .

include::hooks/MetricsService_010-implementation.adoc[]

include::hooks/MetricsService_020-examples-and-usage.adoc[]
