1a16b72e6fd0d4466a983dd75de2ef3b05289b87
[honeycomb.git] / infra / translate-api / src / main / java / io / fd / honeycomb / translate / write / Writer.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.translate.write;
18
19 import com.google.common.annotations.Beta;
20 import io.fd.honeycomb.translate.SubtreeManager;
21 import javax.annotation.Nonnull;
22 import javax.annotation.Nullable;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Base writer, responsible for translation between DataObjects and any other side. Handling all update operations(create,
28  * update, delete)
29  *
30  * @param <D> Specific DataObject derived type, that is handled by this writer
31  */
32 @Beta
33 public interface Writer<D extends DataObject> extends SubtreeManager<D> {
34
35     /**
36      * Process modifications and translate them as create/update/delete operations to lower level
37      *
38      * @param id         Identifier of data being written
39      * @param dataBefore Old data
40      * @param dataAfter  New, updated data
41      * @param ctx        Write context enabling writer to get information about candidate data as well as current data
42      * @throws WriteFailedException if update failed
43      */
44     void processModification(@Nonnull final InstanceIdentifier<? extends DataObject> id,
45                              @Nullable final DataObject dataBefore,
46                              @Nullable final DataObject dataAfter,
47                              @Nonnull final WriteContext ctx) throws WriteFailedException;
48
49     /**
50      * Indicates whether there is direct support for updating nodes handled by this writer,
51      * or they must be broken up to individual deletes and creates.
52      */
53     boolean supportsDirectUpdate();
54 }